批次移動子子資料夾和檔案上一級

批次移動子子資料夾和檔案上一級

我有一個看起來像這樣的目錄

Root Folder
  - Folder A
    - Subfolder
        - File1
        - File2
        - File3
  - Folder B
    - Subfolder
        - File1
        - File2
        - File3
  - Folder C
    - Subfolder
        - File1
        - File2
        - File3

現在我想將子資料夾和檔案向上移動一個級別,並在向上移動後刪除該資料夾,所以它應該看起來像這樣

Root Folder
    - Subfolder
        - File1
        - File2
        - File3
    - Subfolder
        - File1
        - File2
        - File3
    - Subfolder
        - File1
        - File2
        - File3

windows中有沒有批次方法可以做到這一點?

答案1

如果「資料夾 [a|b]」的模式在「子資料夾」的名稱中不重複,那麼是的,這是一個非常簡單的批次腳本。

for /d %%d in ("folder*") do call :doit "%%d"
exit /b

:doit
@echo.Moving contents of "%~1" to "%cd%"...
pushd "%~1"
forfiles /c "cmd /c move @file .."
popd
@echo.Removing "%~1"
rd "%~1"
exit /b

再說一遍,這是非常重要的是要理解這需要資料夾名稱的模式(“資料夾*”)。如果這在您的內容資料夾中複製,那麼您將要遺失資料。

相關內容