Reputation: 2879
I am trying to copy files to a new folder using a windows batch command, but something is not working. I wonder What I am doing wrong.
This works:
xcopy E:\folder\*.wav E:\wav\
But because I have many foldernames and the foldernames, I want to do this for each folder using this command:
xcopy E:\*\*.wav E:\wav\
But now it says:
File not found - *.wav
0 File(s) copied
How should I do this?
Upvotes: 0
Views: 10151
Reputation: 130809
From the command line (no batch):
for /d %F in (e:\*) do @if /i "%F" neq "e:\wav" 2>nul xcopy "%F\*.wav" "e:\wav"
The above will only copy files from the root level folders. If you want all .wav
files from the entire drive, then you need:
for /r "e:\" %F in (.) do @if /i "%F" neq "e:\wav\." 2>nul xcopy "%F\*.wav" "e:\wav"
Double up the percents if you put the command in a batch file.
Note that different files that share the same name from different folders will collide - only one will survive in your \wav folder.
Upvotes: 1
Reputation: 2879
I have done some searching and trying, and this was what I came up with.
for /D %%d in (E:\*) do (
for %%f in (%%d\*.wav) do (
xcopy %%f E:\wav\
)
)
Upvotes: 0