简体   繁体   English

使用 Windows 批处理脚本将多个文件从子文件夹移动到单个文件夹

[英]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.

相关问题 Windows批处理文件,用于将文件从特定的子文件夹移动到另一个文件夹 - Windows batch file to move files from specific subfolders to another folder 如何将特定文件从多个子文件夹移动到各自的父文件夹? (Windows批处理) - How can I move specific files from multiple subfolders to their respective parent folder? (Windows batch) 使用批处理脚本将所有文件从所有子文件夹移动到父文件夹 - Move All Files from all Subfolders to Parent Folder using batch script Windows 批处理脚本,用于从子文件夹和子文件夹中的文件中删除破折号 - Windows batch script to remove dashes from subfolders and the files within subfolders 使用批处理脚本递归重命名文件夹中的文件和子文件夹 - recursively rename files AND subfolders in a folder using batch script Windows批处理将文件从子文件夹复制到一个文件夹 - Windows batch copy files from subfolders to one folder 批处理:将所有文件从多个子文件夹(相同名称)移动到父文件夹中 - Batch: Move all files from multiple subfolders (same name) into the parent 将所有文件从多个子文件夹移至父文件夹 - Move all files from multiple subfolders into the parent folder Windows批处理以覆盖文件夹和子文件夹中的现有文件 - Windows Batch to Overwrite Existing files in folder and subfolders windows 批处理文件脚本,用于从文件夹中选择随机文件并将它们移动到另一个文件夹 - windows batch file script to pick random files from a folder and move them to another folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM