How to move all files with specific extension from

2020-02-19 07:00发布

Folder c:\folder1 contains subfolder1, subfolder2, etc..

These subdirectories hold .pdf and .db files.

How can all the .pdf files be moved to c:\folder1 using the Windows command interpreter?

9条回答
来,给爷笑一个
2楼-- · 2020-02-19 07:34

Robocopy did wonders for me:

 robocopy c:\cache c:\cache-2012 ?????-2012*.hash /S /MOV

I used it to move all files with certain mask out of c:\cache and its numerous subdirectories.

查看更多
Rolldiameter
3楼-- · 2020-02-19 07:40

This worked for me:

for /r "c:\source_directory\" %%x in (*.pdf) do move "%%x" "c:\target_directory\"

This command will copy recursively al pdf files from source to target directory using cmd in windows 7 - tested and works.

Hope it helps.

查看更多
Melony?
4楼-- · 2020-02-19 07:42

The outer for loop lists the sub-directories in the working directory, the inner for loop lists the sub-directories to move to the destination path:

for /d %f in (*.*) do for /d %e in (%f\*.*) do move "%e" DestinationPath

This works best if DestinationPath is not a subfolder of the working directory, as it will try to move DestinationPath into itself.

To confirm the command before running it wholesale, start out just echoing the final move commands like so:

for /d %f in (*.*) do for /d %e in (%f\*.*) do echo move "%e" DestinationPath

and copy/paste one of the results to run it and confirm it worked the way you expected. Then remove the echo and get moving.

查看更多
登录 后发表回答