[英]Batch script to read and extract details from a text file
I need to copy a few files and folders to their respective destinations using a Windows batch script. 我需要使用Windows批处理脚本将一些文件和文件夹复制到它们各自的目标位置。
All the files and folders I am supposed to copy, are kept within a folder, SOURCE
. 我应该复制的所有文件和文件夹都保存在一个文件夹SOURCE
。
Example : 范例 :
C:\\X\\Y\\Z\\SOURCE\\A
文件夹: C:\\X\\Y\\Z\\SOURCE\\A
C:\\X\\Y\\Z\\SOURCE\\A.txt
文件: C:\\X\\Y\\Z\\SOURCE\\A.txt
C:\\X\\Y\\Z\\SOURCE\\B.txt
文件: C:\\X\\Y\\Z\\SOURCE\\B.txt
C:\\X\\Y\\Z\\SOURCE\\ZZZ
文件夹: C:\\X\\Y\\Z\\SOURCE\\ZZZ
The destination paths of all the above are provided as text file contents, destination.txt
. 以上所有内容的目标路径均作为文本文件内容destination.txt
。
Content of destination.txt : destination.txt的内容 :
C:\FinalDestination\D\A\...
C:\FinalDestination\N\A.txt
C:\FinalDestination\C\B.txt
C:\FinalDestination\U\ZZZ\...
Where three dots at the end signifies a directory, otherwise it's a file. 末尾的三个点表示目录,否则为文件。
What I need to do in the above scenario is: 在上述情况下,我需要做的是:
A
from SOURCE
to C:\\FinalDestination\\D\\
将文件夹A
从SOURCE
复制到C:\\FinalDestination\\D\\
A.txt
from SOURCE
to C:\\FinalDestination\\N\\
将文件A.txt
从SOURCE
复制到C:\\FinalDestination\\N\\
B.txt
from SOURCE
to C:\\FinalDestination\\C\\
将文件B.txt
从SOURCE
复制到C:\\FinalDestination\\C\\
ZZZ
from SOURCE
to C:\\FinalDestination\\U\\
将文件夹ZZZ
从SOURCE
复制到C:\\FinalDestination\\U\\
I don't know how to do it as I am pretty new to Windows command line. 我不知道该怎么做,因为我是Windows命令行的新手。
I know XCopy
is a command which can work for me, xcopy source destination
, but I don't know how to extract the source and destination details. 我知道XCopy
是一个对我XCopy
的命令, xcopy source destination
,但是我不知道如何提取源和目标详细信息。
Using an unchanged destination.txt
and your supplied data, the following may help: 使用不变的destination.txt
和您提供的数据,以下操作可能会有所帮助:
@Echo Off
Set "sD=C:\X\Y\Z\SOURCE"
Set "sF=destination.txt"
For /F "UseBackQ Delims=" %%A In ("%sF%"
) Do For %%B In ("%%~fA.") Do echo=XCopy/IY "%sD%\%%~nxB" "%%~dpA." 2>Nul
Pause
You need only modify the content of the variables at lines 3
and 4
您只需要在第3
行和第4
行修改变量的内容
Note : 注意事项 :
I have currently made it so that nothing is copied, just the commands output to your screen. 我目前已经做到了,这样就不会复制任何内容,只是将命令输出到您的屏幕。 If you are happy with the output remove echo=
from line 7
and delete the content of line, 8
如果您对输出满意,请从第7
行删除echo=
并删除第8
行的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.