Page 1 of 1

Batch move files up one directory for multiple directories

Posted: 02 Jun 2011 18:50
by jdp777
I am trying to figure out a way to batch move files from inside a directory up a single directory.

Not sure if I can put what I want to do in words. See in the example below, I have many directories that are like the "1st" and "3rd" directories below. They each have one directory inside of them with files. I would like to batch move all of the files from the directory inside of them and place them in the directory directly above them. Basically the files in the 2nd directory into the 1st directory, the files in the 4th directory into the 3rd directory, etc...

Example:
Root dir
1st dir
2nd dir (files are in this directory)
3rd dir
4th dir (files are in this directory)
...

Not sure if this is possilbe, but any help would be greatly appreciated. I have been having a hard time using google for this one!

JP

Re: Batch move files up one directory for multiple directori

Posted: 02 Jun 2011 20:34
by amel27

Code: Select all

@for /r "C:\TEST\ROOT" %%a in (.) do @(
  pushd "%%a"
  move * .. >Nul 2>&1
  popd
)

Re: Batch move files up one directory for multiple directori

Posted: 02 Jun 2011 21:03
by orange_batch
I can't help you right now, aside from saying that the answer is under for /? where it says "substition of FOR variable references".

Edit: Nvm, amel to the rescue. But you should still learn it.

Re: Batch move files up one directory for multiple directori

Posted: 03 Jun 2011 14:38
by jdp777
Amel, thanks this is great and much appreciated!! Orange_batch, I agree I need to learn it :D !!

I guess I should have mentioned I had subdirectories as well. Does this make it more difficult? I have been experiementing off and on today with this code and not having much luck...

JP

Re: Batch move files up one directory for multiple directori

Posted: 04 Jun 2011 02:15
by Ed Dyreen
.
Try this it will make you an intermediate in notime, you'll then be able to solve most problems yourself.

MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference :arrow:
http://www.allenware.com/icsw/icswidx.htm