从不同的子文件夹分别将文件批量上移一级 [英] Batch move files from different subfolder up one level respectively

查看:874
本文介绍了从不同的子文件夹分别将文件批量上移一级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数百个文件夹,其结构如下:

I have hundreds over folders with structure like this:

  • PARENT\FolderA\Subfolder01\files1.iso
  • PARENT\FolderB\Subfolder02\files2.iso
  • PARENT\FolderC\Subfolder03\files3.iso
  • PARENT\FolderA\Subfolder01\files1.iso
  • PARENT\FolderB\Subfolder02\files2.iso
  • PARENT\FolderC\Subfolder03\files3.iso

我想将所有files1.isofiles2.isofiles3.iso分别上移一个级别.应该看起来像这样.

I want to move all the files1.iso, files2.iso, files3.iso up one level respectively. Should look like this.

  • PARENT\FolderA\files1.iso
  • PARENT\FolderB\files2.iso
  • PARENT\FolderC\files3.iso
  • PARENT\FolderA\files1.iso
  • PARENT\FolderB\files2.iso
  • PARENT\FolderC\files3.iso

更好的方法是删除不需要的Subfolder01Subfolder02Subfolder03.

And what would be even better is something that work to delete the Subfolder01, Subfolder02, Subfolder03 which are not wanted.

如果可能的话,也分别将files1.isofiles2.isofiles3.iso重命名为FolderA.isoFolderB.isoFolderC.iso.

And if possible, as well batch rename those files1.iso, files2.iso, files3.iso to the name of FolderA.iso, FolderB.iso, FolderC.iso respectively.

我真的不知道如何解决这个问题.有人可以帮忙吗?

I really have no idea how to work this out. Anybody can help?

推荐答案

cd PARENT
for /D %%i in (*) do (
  for /D %%j in (%%i\*) do (
    move "%%j\*" "%%i\%%i.iso" 2>&1>nul && rmdir "%%j" 2>&1>nul
  )
)

说明:

cd PARENT

只需确保您在根目录下即可正常工作,因此其余工作正常

Just make sure you're in the root directory to work from so the rest works

for /D %%i in (*) do (

这是一个for循环,对于工作目录中的每个目录,它都将%% i设置为目录名(例如FolderA),然后执行以下操作:

This is a for loop, for every directory in the working directory it sets %%i to the directory name (e.g. FolderA), then does the following:

  for /D %%j in (%%i\*) do (

这是一个嵌套的for循环,对于%% i中的每个目录(在第一个循环中,FolderA),它将%% j设置为目录名(在第一个循环中,FolderA \ Subfolder01),然后执行以下操作:

This is a nested for loop, for every directory in %%i (on first loop, FolderA) it sets %%j to the directory name (on first loop, FolderA\Subfolder01), then does the following:

    move "%%j\*.iso" "%%i\%%i.iso" 2>&1>nul && rmdir "%%j" 2>&1>nul

将名称在%% j(FolderA \ Subfolder01)中以.iso结尾的所有内容移动到%% i(FolderA),并将其重命名为%% i.iso(FolderA.iso).如果可行,请删除%% j目录.将所有输出重定向到nul(即不产生任何输出).

Move everything whose name ends with .iso in %%j (FolderA\Subfolder01) to %%i (FolderA), and rename it to %%i.iso (FolderA.iso). If that works, remove the %%j directory. Redirect all output to nul (i.e. produce no output).

  )
)

关闭循环.

这篇关于从不同的子文件夹分别将文件批量上移一级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆