← Monitor website | php read and print csv file →

Move/Copy several files to the same directory

| tags: windows, batch

Let’s say you want to copy all your mp3 files into the same directory but you want to disregard the current directory structure, how do you do that? xcopy and robocopy will not help as they will keep the current directory structure. The solution is to use the “for” command as follows, from the command line :

for /r c:\mp3 %1 in (*.mp3) do copy "%1" c:\allmp3

or from a batch file :

for /r c:\mp3 %%1 in (*.mp3) do copy "%%1" c:\allmp3

Both these commands will copy all mp3 contained in c:\mp3 and all its subdirectories to the allmp3 directory with all files at the same level. If you want to move the files instead, just replace the “copy” command by the “move” command.