如何将文件从文件夹树中具有固定名称的子文件夹移动到其具有不同名称的父文件夹?

问题描述 投票:0回答:1

我有很多图片位于单独的文件夹中,但每个文件夹也在一个文件夹内。看起来像这样

<path>\(nameoffolder)\full\

我想将名为

full
的文件夹中的所有图像移动到其父文件夹
(nameoffolder)

(nameoffolder)
不是一个连续的数字或任何东西,但其名称变化很大。

有没有办法批量执行此操作,最好使用命令行?

batch-file cmd subdirectory
1个回答
0
投票

用根目录路径替换

C:\Temp
后,使用此批处理文件执行此简单任务:

@echo off

rem For each subdirectory in the specified directory check if there is
rem a subdirectory with name "full" containing one or more files. If
rem this condition is true, move the files from subdirectory "full"
rem to its parent directory and then delete the subdirectory "full".

for /D %%I in ("C:\Temp\*") do (
    if exist "%%I\full\*" (
        echo Moving files to %%I ...
        move /Y "%%I\full\*" "%%I" >nul
        rd "%%I\full"
    )
)

要了解所使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完整、仔细地阅读每个命令显示的帮助页面。

  • echo /?
  • for /?
  • if /?
  • move /?
  • rem /?
  • rd /?
© www.soinside.com 2019 - 2024. All rights reserved.