I have a batch file which will copy all the files from one location to another location.
我有一个批处理文件,它将所有文件从一个位置复制到另一个位置。
But i want to display the file name which was copying to another location when i run the batch file.
但我想显示当我运行批处理文件时复制到另一个位置的文件名。
Example:
copy /-y "%File%\Sample.exe" "%DestinationDrive%"
I have the command like above in my batch file, but when i run the batch file i was getting the output in cmd window as "1 file(s) copied."
我在批处理文件中有上面的命令,但是当我运行批处理文件时,我在cmd窗口中输出“1个文件被复制”。
Instead of that i need the output like "Sample.exe copied."
而不是我需要输出像“Sample.exe复制”。
How can I do this?
我怎样才能做到这一点?
1 个解决方案
#1
1
Here are 2 simple methods to achieve this.
以下是实现此目的的两种简单方法。
The better method is to avoid the temp file and add all the files you want to copy, to a variable in the script, in this case called myfiles
.
更好的方法是避免临时文件并将要复制的所有文件添加到脚本中的变量,在本例中称为myfiles。
We just iterate through the variable entries and process each one. This example also pipes the copy
process to nul
which will only allow you to see the echo of each filename, instead of the actual copy process.
我们只是迭代变量条目并处理每个条目。此示例还将复制过程传递给nul,这将只允许您查看每个文件名的回显,而不是实际的复制过程。
@echo off
set myfiles="example.exe","example2.dll","example3.txt","example4.inf"
for %%i in (%myfiles%) do (
copy /-y "%file%\%%~i" "%DestinationDrive%" >nul && echo Copied %%~i
)
So my example result is:
所以我的例子结果是:
D:\>simulate.cmd
Copied example1.exe
Copied example2.dll
Copied example3.txt
Copied example4.inf
The Temp file method:
临时文件方法:
Create a file with the files you want to copy:
使用要复制的文件创建文件:
Filename.txt
file.txt
this_file.exe
example.dll
somefile.txt
then create a batch file:
然后创建一个批处理文件:
batchfile.cmd
@echo off
for /f "delims=" %%i in (filename.txt) do (
copy /-y "%File%\%%i" "%DestinationDrive%" > nul && echo Copied %%i
)
PS!! I used you /-y
as per your example, if you want to actually over write files without prompting for confirmation, rather use /y
PS!我根据你的例子使用了你/ -y,如果你想在不提示确认的情况下实际过度写文件,而是使用/ y
#1
1
Here are 2 simple methods to achieve this.
以下是实现此目的的两种简单方法。
The better method is to avoid the temp file and add all the files you want to copy, to a variable in the script, in this case called myfiles
.
更好的方法是避免临时文件并将要复制的所有文件添加到脚本中的变量,在本例中称为myfiles。
We just iterate through the variable entries and process each one. This example also pipes the copy
process to nul
which will only allow you to see the echo of each filename, instead of the actual copy process.
我们只是迭代变量条目并处理每个条目。此示例还将复制过程传递给nul,这将只允许您查看每个文件名的回显,而不是实际的复制过程。
@echo off
set myfiles="example.exe","example2.dll","example3.txt","example4.inf"
for %%i in (%myfiles%) do (
copy /-y "%file%\%%~i" "%DestinationDrive%" >nul && echo Copied %%~i
)
So my example result is:
所以我的例子结果是:
D:\>simulate.cmd
Copied example1.exe
Copied example2.dll
Copied example3.txt
Copied example4.inf
The Temp file method:
临时文件方法:
Create a file with the files you want to copy:
使用要复制的文件创建文件:
Filename.txt
file.txt
this_file.exe
example.dll
somefile.txt
then create a batch file:
然后创建一个批处理文件:
batchfile.cmd
@echo off
for /f "delims=" %%i in (filename.txt) do (
copy /-y "%File%\%%i" "%DestinationDrive%" > nul && echo Copied %%i
)
PS!! I used you /-y
as per your example, if you want to actually over write files without prompting for confirmation, rather use /y
PS!我根据你的例子使用了你/ -y,如果你想在不提示确认的情况下实际过度写文件,而是使用/ y