简体   繁体   English

将所有文件从多个子文件夹移至父文件夹

[英]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 . 意味着过程的目录Album1Album2Album3与批处理文件目录是FlacrootOnmyo-Za - Welter of Hundred DemonsOnmyo-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.

相关问题 使用批处理脚本将所有文件从所有子文件夹移动到父文件夹 - Move All Files from all Subfolders to Parent Folder using batch script 如何将特定文件从多个子文件夹移动到各自的父文件夹? (Windows批处理) - How can I move specific files from multiple subfolders to their respective parent folder? (Windows batch) 我坚持使用 powershell 脚本,该脚本必须将多个子文件夹中的所有文件压缩到目标文件夹 - Im stuck on a powershell script that has to compress all files from multiple subfolders to a destination folder 将文件夹中的所有文件及其所有子文件夹移动到一个大文件夹中 - windows xp - move all files in a folder and all it's subfolders into one big folder - windows xp 如何使用 windows 命令将所有文件从父文件夹中移动到新的子文件夹中? - How to move all files excecpt one from parent folder into a new child folder using windows command? 将子文件夹中的文件移动到文件夹并重命名Windows提示符 - Move files in subfolders to a folder and rename windows prompt Powershell 将特定文件从所有子文件夹复制到单个文件夹 - Powershell copying specific files from all subfolders to a single folder 列出R中没有子文件夹的文件夹中的所有文件 - List all files in a folder without subfolders in R Select 使用 OSQuery 的文件夹和子文件夹中的所有文件 - Select all files in a folder and subfolders with OSQuery 从子文件夹中解压缩并重命名为父文件夹 - unrar from subfolders and rename to parent folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM