用于将文件从一个地方复制到另一个地方的批处理文件
如何编写一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建像“copy_file.cmd”这样的批处理文件,并输入以下内容:
如果目标文件不存在,它将把源文件复制到目标。
/V
开关使复制验证文件是否已正确复制,并且是可选的。SRC
中的%~dp0
从变量%0< 获取驱动器
d
和路径p
/code>(批处理文件的路径)并使用该路径作为file.dll
的前缀。您希望执行此操作以保证脚本始终从与批处理文件相同的目录而不是当前目录中获取文件。例如,如果您的批处理文件位于映射到H:
的网络驱动器上,您仍然可以从C:
运行它。Create your batch file like "copy_file.cmd" and put in these contents:
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
inSRC
takes the drived
and pathp
from the variable%0
(the batch file's path) and uses that path as a prefix tofile.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 toH:
, you could still run it fromC:
.