Page 1 of 1

Almost there - Lil Help Pretty please? :-)

Posted: 05 Sep 2011 09:15
by DosNewb
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!

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

Posted: 05 Sep 2011 17:39
by aGerman
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

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

Posted: 05 Sep 2011 18:25
by DosNewb
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

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

Posted: 02 Jul 2013 14:51
by kalmiya
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!