Reputation: 321
I have a folder with a lot of sub folders with one or more files in each. I am trying to write a batch file that moves all those files to C:\songs (for example). Any help? I have already tried
C:\>FOR /R C:\Test %i IN (*) DO MOVE %i C:\Songs
The folders Test and songs exist, but I get an error saying
%i was unexpected at this time.
What am I doing wrong?
Upvotes: 9
Views: 40246
Reputation: 51
(move files in sub-directories up 1)
for /r %x in (*.*) do move "%x" "%x"/../..
(last part I usually use backward slants but this crazy thing kept deleting them for some reason. It'll work either way though)
(delete unneeded directories)
for /d /r %x in (bin) do rd "%x"
i.e., if you had a bunch of directories with files in "bin" directories under those and you wanted to move everything up 1 and delete the "bin" directories.
Upvotes: 5
Reputation: 2074
FOR /R %i IN (C:\Test\*) DO MOVE "%i" C:\Songs
In a batch file, it has to be %%i. Weird quirk of batch.
Upvotes: 5