user3366812
user3366812

Reputation: 1

Batch File to move avi up a directory

I need to move lots of .avi files out of folders up one directory and each folder has a unique name, I've googled lots of scripts and not found any working way to do this. If anyone could give me some help that would be great.

eg:

I want to move all the .avi's in the Sub-directorys into the Main-directory.

Thanks!

Upvotes: 0

Views: 152

Answers (2)

MC ND
MC ND

Reputation: 70961

for /d %%f in ("c:\directory\*") do (
    if exist "%%~ff\*.avi" echo move "%%~ff\*.avi" "%%~dpf"
)

List of move commands is echoed to console. If it is correct, remove the echo command

EDITED - Code included was written for batch file usage and confortable screen read. For command line usage, it is necessary to replace the double percent signs with single percent signs, and is easier to write it in a single line.

for /d %f in ("c:\directory\*") do @if exist "%~ff\*.avi" @echo move "%~ff\*.avi" "%~dpf"

The included @ signs (not necessary) are to hide the command execution. That way, the only output to console is the echo command. And as in the previous code, if output is correct, run it again without the echo command to execute the move operation

Upvotes: 3

Monacraft
Monacraft

Reputation: 6620

Try this:

set root=C:\PathtoMain\Main\
pushd "%root%"

for /r %%a in (*.avi) do (
move "%%~a" "%root%"
)

popd

And that should solve your problem.

Mona.

Upvotes: 0

Related Questions