Batch move files up one directory for multiple directories

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jdp777
Posts: 2
Joined: 02 Jun 2011 18:32

Batch move files up one directory for multiple directories

#1 Post by jdp777 » 02 Jun 2011 18:50

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Batch move files up one directory for multiple directori

#2 Post by amel27 » 02 Jun 2011 20:34

Code: Select all

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

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Batch move files up one directory for multiple directori

#3 Post by orange_batch » 02 Jun 2011 21:03

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.

jdp777
Posts: 2
Joined: 02 Jun 2011 18:32

Re: Batch move files up one directory for multiple directori

#4 Post by jdp777 » 03 Jun 2011 14:38

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Batch move files up one directory for multiple directori

#5 Post by Ed Dyreen » 04 Jun 2011 02:15

.
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

Post Reply