简体   繁体   English

Windows 命令复制文件而不提示输入 bat 文件

[英]Windows command to copy file without any prompts for bat file

I would like to make a.bat file which will make a backup for my kdbx file.我想制作一个 .bat 文件,该文件将为我的 kdbx 文件进行备份。 I have two simple commands there.我有两个简单的命令。

cd C://Access
xcopy access4.kdbx access4.backup.kdbx /Y

but the second one ask me: Does access4.backup.kdbx specify a file name or directory name on the target (F = file, D = directory)?但第二个问我:access4.backup.kdbx 是否在目标上指定了文件名或目录名(F = 文件,D = 目录)?

I dont understand why Windows does not recognize the file in the source.我不明白为什么 Windows 无法识别源中的文件。 Also I don't see any option to set it up in the command.我也看不到在命令中设置它的任何选项。 How can I solve it?我该如何解决?

You are mixing simple and multiple copying of files:您正在混合文件的简单和多次复制:

xcopy is to be used for copying multiple files. xcopy用于复制多个文件。

copy is to be used for copying just one file. copy仅用于复制一个文件。

So, your command should be:所以,你的命令应该是:

copy /Y access4.kdbx access4.backup.kdbx

To begin with, the Windows path separator is \ but not / or // .首先,Windows 路径分隔符是\但不是///

Then you should use cd /D rather than plain cd since you specified also a drive letter.然后你应该使用cd /D而不是普通的cd因为你还指定了一个驱动器号。


The quick solution is to use copy rather than xcopy , because it does not show such a prompt:快速的解决方案是使用copy而不是xcopy ,因为它不会显示这样的提示:

cd /D "C:\Access"
copy /Y "access4.kdbx" "access4.backup.kdbx"

However, xcopy features a lot of additional options in contrast to copy , so the latter might not help in certain situations.但是,与copy相比, xcopy具有许多附加选项,因此后者在某些情况下可能无济于事。


To avoid the prompt, you could pre-create the destination file and let xcopy overwrite it:为避免出现提示,您可以预先创建目标文件并让xcopy覆盖它:

cd /D "C:\Access"
>> "access4.backup.kdbx" rem/
xcopy /Y "access4.kdbx" "access4.backup.kdbx"

See also this answer .另请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM