[英]Move Multiple Files from Subfolders to Single Folder using Windows batch script
I have a requirement where the files are present in folders and the subfolders.我有一个要求,文件存在于文件夹和子文件夹中。 The subfolders are dynamically created with current date and time.
子文件夹是使用当前日期和时间动态创建的。 All the files should be moved to one destination folder without the subfolders.
所有文件都应移动到一个目标文件夹,而没有子文件夹。
Folder A:文件夹A:
1.txt
2.txt
Folder 20180907-1240-008
3.txt
4.txt
Folder 20180907-1128-001
5.txt
6.txt
Folder 20180906-0040-010
7.txt
8.txt
The destination folder should look like below目标文件夹应如下所示
Folder B:文件夹 B:
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
the below command works in command prompt下面的命令在命令提示符下工作
for /r %d in (*) do copy "%d" "F:\Tickets\Movement\390558-Harmony-LCOPYREC\B
My batch script looks like below我的批处理脚本如下所示
@echo off
cd /d "A"
for /r %%d in (*) do copy "%d" "F:\Tickets\B"
I have an error as below while executing in a batch script在批处理脚本中执行时出现如下错误
\Tickets\B\*
The system cannot find the file specified.
0 file(s) copied.
How do I make the script working我如何使脚本工作
I used the following command in cmd to copy all m4a files from music folder and its all subfolder in another folder my-music.我在 cmd 中使用以下命令复制音乐文件夹中的所有 m4a 文件及其在另一个文件夹 my-music 中的所有子文件夹。 Don't forget "\\" after your destination folder path.
不要忘记目标文件夹路径后的“\\”。
for /r "c:\Users\A\Desktop\music" %x in (*.m4a) do copy "%x" "c:\Users\A\Desktop\my-music\"
Almost right, no need to CD, just specify the parent path to folder after /r
also ensure you double quote correctly and preferbly put a backslash at the end of a path to copy to:几乎是对的,不需要 CD,只需在
/r
之后指定文件夹的父路径,还要确保正确使用双引号,并最好在要复制到的路径末尾添加反斜杠:
for /r "C:\path to folderA" %%d in (*) do copy "%%d" "F:\Tickets\Movement\390558-Harmony-LCOPYREC\B\"
if you do not want to copy all files and just .txt
for example, simply change your criteria to (*.txt)
例如,如果您不想复制所有文件而仅复制
.txt
,只需将条件更改为(*.txt)
for /r "C:\path to folderA" %%d in (*.txt) do copy "%%d" "F:\Tickets\Movement\390558-Harmony-LCOPYREC\B\"
Also, not sure which path you really want as destination, but you can do:另外,不确定您真正想要哪条路径作为目的地,但您可以这样做:
@echo off
set "dest=F:\Tickets\B\"
set "source=C:\some dir\A"
for /r "%source%" %%d in (*) do copy "%%d" "%dest%"
Copy and paste above code is into the batch file.将上面的代码复制并粘贴到批处理文件中。
如果您想从 cmd 执行此操作,请指定/n
之后的父文件夹路径,例如for /r "C:\\parentFolderPath\\" %d in (*) do copy "%d" "D:\\destinationFolderPath\\"
don'不要忘记在路径的末尾放置反斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.