Almost there - Lil Help Pretty please? :-)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DosNewb
Posts: 2
Joined: 05 Sep 2011 08:52

Almost there - Lil Help Pretty please? :-)

#1 Post by DosNewb » 05 Sep 2011 09:15

Hi Folks,

I need to move the contents of subfolders to the top level folder. I found this script which works on my Win7 PC:

FOR /f "delims=" %a IN ('DIR *.* /s /b') DO MOVE "%a"

I need to answer "a" for All when overwriting, would like to just do it automatically if possible (minor issue).

Here is the main question:

I have 740 top level folders this needs to be done in. (Itunes, each top folder is a musician, and each musician has many album/folders).

I Really, Really don't want to have to run this 740 times manually.

My folders are set up like this:

J:\Musicfiles\<Artist Name>\<Album Names>\files

Is there a way to loop through each Artist Name top level folder in Musicfiles and run this script against each artist? The result would be that each artist "top level" folder would have all the files for that artist in it. (To be clear, I don't want all files for ALL artists in one folder).

By having the script automatically overwrite duplicates, I would get rid of the many duplicate files I have. It would also make manually editing the file names etc for each artist easier, since they would all be visible at once, rather than buried in separate sub folders.

Last question. After this is done, could I then get a 2nd script to delete all sublevel folders (which would now be empty) for each artist?

Many thanks!

aGerman
Expert
Posts: 4740
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Almost there - Lil Help Pretty please? :-)

#2 Post by aGerman » 05 Sep 2011 17:39

Untested:

Code: Select all

@echo off
set "root=J:\Musicfiles"

for /f "delims=" %%a in ('dir /ad /b "%root%"') do (
  for /f "delims=" %%b in ('dir /a-d /b /s "%root%\%%a"') do (
    move /y "%%b" "%root%\%%a\"
  )
  for /f "delims=" %%b in ('dir /ad /b "%root%\%%a"') do (
    rd /s /q "%root%\%%a\%%b"
  )
)

Regards
aGerman

DosNewb
Posts: 2
Joined: 05 Sep 2011 08:52

Re: Almost there - Lil Help Pretty please? :-)

#3 Post by DosNewb » 05 Sep 2011 18:25

WOW! You are a genius. I am amazed. I had no idea DOS commands could be so powerful (in the right hands).

Your script allowed me to do in about a minute what I would never even been able to attempt by hand. My hat is truly off to you aGerman.

You have my most sincere thanks and respect. :D

kalmiya
Posts: 1
Joined: 02 Jul 2013 14:10

Re: Almost there - Lil Help Pretty please? :-)

#4 Post by kalmiya » 02 Jul 2013 14:51

Thanks - tried it on win7 pro (running in a vmware virtual machine) and for some reason C:\mydir doesn't work.
Changed it to "." (dot) and then ran it from within that directory and that works like a charm.

Great tip - will save me hours of manually moving files around!

Post Reply