[英]Move all files from multiple subfolders into the parent folder
I found a nice script at https://superuser.com/questions/999922/move-all-files-from-multiple-subfolders-into-the-parent-folder 我在https://superuser.com/questions/999922/move-all-files-from-multiple-subfolders-into-the-parent-folder中找到了一个不错的脚本
The main problem is I need a script which works for every subfolder and moves all files to the folder above from the Flacroot directory as initial point. 主要问题是我需要一个适用于每个子文件夹的脚本,并将所有文件从Flacroot目录移到上方的文件夹作为初始点。 For example Album1 --> Re-Encode, all content off Re-Encode should be moved to Album1 and that for every Album directory.
例如,“专辑1->重新编码”,“重新编码”中的所有内容都应移到“专辑1”中,并移到每个“专辑”目录中。
@echo off
FOR /R "C:\Source Folder" %%i IN (*.png) DO MOVE "%i" "C:\Staging Folder"
This script cannot do it for every subfolder. 该脚本不能对每个子文件夹都执行此操作。 Has someone has an idea how that could be solved?
是否有人知道如何解决?
From: 从:
|Flacroot
| |Album1
| | |Re-Encode
| | | |*.*
|Flacroot
| |Album2
| | |Re-Encode
| | | |*.*
|Flacroot
| |Album3
| | |Re-Encode
| | | |*.*
to: 至:
|Flacroot
| |Album1
| | |Re-Encode, *.*
|Flacroot
| |Album2
| | |Re-Encode, *.*
|Flacroot
| |Album3
| | |Re-Encode, *.*
Original and edited structure: 原始结构和编辑结构:
D:.
│ cuerenamer.bat
│
└───!Onmyōza
│
├───Onmyo-Za - Welter of Hundred Demons
│ │ Front.jpg
│ │
│ ├───Re-Encode
│ │ 01. Song1.flac
│ │ 02. Song2.flac
│ │
│ └───Scans
│ 02.jpg
│ 03.jpg
│
│───Onmyo-Za - Ninja Magic Story of Voluptuous Flower
│ │ Front.jpg
│ │
│ ├───Re-Encode
│ │ 01. Song1.flac
│ │ 02. Song2.flac
│ │
│ └───Scans
│ 02.jpg
│ 03.jpg
│ 04.jpg
Oh and important the Scans
folder should be excluded and should not be touched. 哦,重要的是应该排除“
Scans
文件夹,并且不要触摸它。 I hope this structure explains that good enough. 我希望这种结构足以说明这一点。
The script should run in the parent folder !Onmyōza
and move the files as described. 该脚本应在父文件夹
!Onmyōza
运行,并按照说明移动文件。
Thank you! 谢谢!
This task is easy to achieve with the following batch code: 使用以下批处理代码可以轻松实现此任务:
@echo off
for /D %%I in ("%~dp0*") do (
if exist "%%I\Re-Encode\*" (
move /Y "%%I\Re-Encode\*" "%%I\" 2>nul
rd "%%I\Re-Encode" 2>nul
)
)
%~dp0
references the drive and path of the batch file which is expanded to a directory path always ending with a backslash. %~dp0
引用批处理文件的驱动器和路径,该文件已扩展为始终以反斜杠结尾的目录路径。
Command FOR with option /D
searches for non-hidden directories matching the pattern *
in directory of the batch file. 带选项
/D
命令FOR在批处理文件目录中搜索与模式*
匹配的非隐藏目录。 This means FOR processes the directories Album1
, Album2
and Album3
with batch file being in directory Flacroot
or Onmyo-Za - Welter of Hundred Demons
and Onmyo-Za - Ninja Magic Story of Voluptuous Flower
with batch file being in directory !Onmyōza
. 这意味着过程的目录
Album1
, Album2
和Album3
与批处理文件目录是Flacroot
或Onmyo-Za - Welter of Hundred Demons
和Onmyo-Za - Ninja Magic Story of Voluptuous Flower
在目录中的批处理文件是!Onmyōza
。
The IF condition checks if there is in current subdirectory of the batch file's directory as found by FOR a subdirectory Re-Encode
. IF条件检查在FOR子目录
Re-Encode
找到的批处理文件目录的当前子目录中是否存在。
If there is a subdirectory Re-Encode
, all files in this subdirectory are moved one directory level up to current subdirectory in batch file directory. 如果存在子目录
Re-Encode
,则此子目录中的所有文件都将一个目录级别上移到批处理文件目录中的当前子目录。
Then the subdirectory Re-Encode
is removed which works only if it does not contain anymore any files or other subdirectories and not running process use this directory as current directory. 然后,子目录“
Re-Encode
被删除,该子目录仅在不再包含任何文件或其他子目录并且不运行进程时才使用此目录作为当前目录,该目录才起作用。
Error messages which could be output because of a file to move already exists in the album directory and being read-only, or the file to move is opened in an application resulting in a sharing access violation, or subdirectory Re-Encode
is not empty on deletion, ... are suppressed by redirecting them from handle STDERR to device NUL . 相册目录中已经存在由于移动文件而可能输出的错误消息,并且为只读状态,或者在应用程序中打开了移动文件,导致共享访问冲突,或者子目录中的
Re-Encode
不为空通过将它们从句柄STDERR重定向到设备NUL来抑制删除...。
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully. 为了了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读每个命令显示的所有帮助页面。
call /?
... explaining %~dp0
%~dp0
echo /?
for /?
if /?
move /?
rd /?
Read also the Microsoft article about Using Command Redirection Operators for an explanation of 2>nul
. 另请参阅Microsoft有关使用命令重定向操作符的文章, 以获取
2>nul
的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.