用于将文件从一个地方复制到另一个地方的批处理文件

发布于 2024-10-01 14:04:25 字数 131 浏览 0 评论 0原文

如何编写一个bat文件,该文件能够将与.bat文件位于同一文件夹中的file.dll放入windowsMainDir/中system32 文件夹,但仅当该文件尚不存在时?

How can I program a bat file that would be capable of putting file.dll that is in the same folder that a .bat file is in into the windowsMainDir/system32 folder but only if the file does not already exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紅太極 2024-10-08 14:04:25

创建像“copy_file.cmd”这样的批处理文件,并输入以下内容:

@echo off
SET SRC="%~dp0file.dll"
SET DEST="%WINDIR%\system32\file.dll"
if not exist %DEST% copy /V %SRC% %DEST%

如果目标文件不存在,它将把源文件复制到目标。 /V 开关使复制验证文件是否已正确复制,并且是可选的。

SRC 中的 %~dp0 从变量 %0< 获取驱动器 d 和路径 p /code>(批处理文件的路径)并使用该路径作为 file.dll 的前缀。您希望执行此操作以保证脚本始终从与批处理文件相同的目录而不是当前目录中获取文件。例如,如果您的批处理文件位于映射到 H: 的网络驱动器上,您仍然可以从 C: 运行它。

c:\> h:\shared_scripts\copy_file.cmd

Create your batch file like "copy_file.cmd" and put in these contents:

@echo off
SET SRC="%~dp0file.dll"
SET DEST="%WINDIR%\system32\file.dll"
if not exist %DEST% copy /V %SRC% %DEST%

If the destination file does not exist, it will copy the source file to the destination. The /V switch makes copy verify that the file was copied correctly, and is optional.

The %~dp0 in SRC takes the drive d and path p from the variable %0 (the batch file's path) and uses that path as a prefix to file.dll. You want do do this to guarantee that the script always takes the file from the same directory as the batch file, and not the current directory. E.g., if your batch file was on a network drive mapped to H:, you could still run it from C:.

c:\> h:\shared_scripts\copy_file.cmd
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文