How can I move all files to the parent folder using windows cmd command

青春壹個敷衍的年華 提交于 2019-12-25 05:16:19

问题


For Example:

I have

  • C:\Folder\Subfolder1\SubfolderA\file1.pdf
  • C:\Folder\Subfolder1\SubfolderB\file2.pdf
  • C:\Folder\Subfolder1\Subfolderc\file3.pdf

And I just want to have this path:

  • C:\Folder\Subfolder1\SubfolderA
  • C:\Folder\Subfolder1\SubfolderB
  • C:\Folder\Subfolder1\Subfolderc
  • C:\Folder\Subfolder1\file1.pdf
  • C:\Folder\Subfolder1\file2.pdf
  • C:\Folder\Subfolder1\file3.pdf

I am using Windows 7, and tried different commands in CMD, like:

Move C:\Folder\Subfolder1\SubfolderA\*.* C:\Folder\Subfolder1\SubfolderA

I spent almost a day exploring different solutions to do this since I am working around thousands of files; and so impractical to do this manually.


回答1:


I think I understood you correctly, so, below there's the solution.

Imagine there are two folders:

C:\ABC

and C:\ABC\XYZ

to transfer all files from C:\ABC\XYZ to C:\ABC do the following:

  1. Navigate to C:\ABC\XYZ

  2. Execute the command: move *.* ..

and that's it.

All files from C:\ABC\XYZ will be moved to the parent folder, i.e to C:\ABC\

Below, there are pictures to demonstrate this solution.

  • Folder ABC contains XYZ folder

  • we navigate to XYZ and there are some files exist

  • We execute move *.* .. command to transfer files to the parent (ABC) folder

  • now XYZ is empty

And all files from XYZ are in ABC (parent folder) now




回答2:


Try this command

for /d %A in ("D:\Shawu\Access\Main\*") do @(pushd "%A"&(for /r /d %B in (*) do @move /y "%B\*" "%A" 2>nul)&popd)

Be careful of files with duplicate names. It will overwrite. I would recommend you to try first with some test file to see whether you get the desired results.

Thanks!



来源:https://stackoverflow.com/questions/25540926/how-can-i-move-all-files-to-the-parent-folder-using-windows-cmd-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!