Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move all files with specific extension from all subdirectories to their parent using CMD?

Tags:

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?

like image 275
mihai Avatar asked Dec 05 '10 03:12

mihai


People also ask

How can we list down all the files and subfolders and their details from CLI?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.


1 Answers

This worked for me:

In a .bat / .cmd file:

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

For direct input into a Command Prompt window (not PowerShell):

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

This command will copy recursively all *.pdf files from the source (and all of its subdirectories) to the target directory.

To exclude files in subdirectories omit the /r switch.

Hope it helps.

like image 165
pablo M Avatar answered Oct 01 '22 03:10

pablo M