Computer Hope

Microsoft => Microsoft DOS => Topic started by: cameronyoung on January 11, 2010, 06:24:46 PM

Title: Moving many files up one directory level
Post by: cameronyoung on January 11, 2010, 06:24:46 PM
Hi,

I have about 400 folders with the following directory depth:
Level1\Level2\Level3\*.files

I need to move all of the *.files up one directory so that they are:
Level1\Level2\*.files

It would also be extremely helpful if I could limit the *.files to specific types of files, namely *.MP3 and then if I could delete the "Level3" directories and any remaining junk files they contain.

I'm sure this solution is possible in with a BAT file?

Thank you.
Title: Re: Moving many files up one directory level
Post by: Geek-9pm on January 11, 2010, 07:00:05 PM
I would not recommend a bat file.
Do you have a backup device?
Do you have lots of free space on your disk?
Rather that move, you should copy.

But if you insist. You are gong to skip over one on folder, the top one.
Level1\Level2\Level3\*.files

The Level1 folder will not be moved.

We shall move the contents of the next folder down to a new, higher location. Later you can rename the folders, if you wish.


Make a new folder. call it Level2New.
This is going to be the target folder. Make it at the highest level.

In windows explore open the  the Level2 fonder.
Now look up on the tool bar. See the 'Edit' tab?
Click on Edit,  Select all.
Then Click on Move to folder.
Select the Level2New as the target.
 If you do it right the contents of Level2 and everything below will be in Level2New.
Level1 will still have its contents.
Practice on some dummy folders first.
Title: Re: Moving many files up one directory level
Post by: BC_Programmer on January 11, 2010, 07:21:32 PM
the folders aren't being moved... the files are.



Code: [Select]
@echo off
for /f %%P in ('dir /b /od') do copy %%P\*.* .
REM for /f %%P in (dir /b /od') do rmdir /s /q %%P

Run this batch file from within the "level2" folder. what it does is copy all files from the folders within level2 into the level2 folder itself. (as I understand your issue, you have many folders within this level2 folder, and wish to copy the files from each of these folders to the parent folder.

Note that I am using the "copy" command, at this point. the loop that removes the directories is commented out. I recommend making a complete backup, if at all possible, before deleting them. Or, you could change the command to move. a Move is faster then a copy and delete on the same drive. Also, you can easily change the filemask by changing the %%P\*.* to %%P\*.mp3, for example.

also, remember that if any of these folders has filenames that are the same as files in any other folder, you should rename them. the copy command as written will prompt you to overwrite if any names conflict.

Title: Re: Moving many files up one directory level
Post by: BillRichardson on January 11, 2010, 07:28:18 PM
Code: [Select]
@echo off
cd "C:\Documents and Settings\cameronyoung\Level1\Level2\Level3\"

copy *.mp3  "C:\Documents and Settings\cameronyoung\Level1\Level2\"

delete *.*
 
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 11, 2010, 07:41:06 PM
Hi, I don't think I explained myself as clearly as I could have. I really need something that will loop through a number of folders, a better explanation of my 400 odd folders would be like this:

Level1\1Level2\Level3\*.files
Level1\2Level2\Level3\*.files
Level1\3Level2\Level3\*.files
Level1\4Level2\Level3\*.files
Level1\5Level2\Level3\*.files
Level1\6Level2\Level3\*.files

What I want to do is to remove all of the "Level 3" folders and move the contents (well, just .MP3 files if possible) back to the "Level 2" folders.  It's easy to do it for one folder, but I've got about 400 folders at "Level 2" which each contain an extra, unwanted folder.

Even if the script or whatever doesn't delete the "Level 3" folders in the end, that's not a big deal, as I have a program that could remove them.. though it would be preferable.

Thanks for your help.
Title: Re: Moving many files up one directory level
Post by: BC_Programmer on January 11, 2010, 07:50:24 PM
Ahh, OK, guess I misunderstood :)

Code: [Select]
@echo off
for /f %%P in ('dir /b /od') do copy %%P\level3\*.*  .\%%P\
REM for /f %%P in (dir /b /od') do rmdir /s /q %%P\level3

Run this from within your "level1" folder. it will do something similar to the previous batch I provided; this one loops through all the folders ('dir /b /od') and copies the files from within the level3 folder of that folder "out" of the folder into the "level2" folder that it's looping through.

Again, the remarked out rmdir command will remove the level3 folders, as well. the first loop only copies. and change the "%%P\level3\*.*" to "%%P\level3\*.mp3" to only copy mp3 files. (as I'm sure your aware deleting the folder will result in the loss of other files that are not MP3 from within that folder.
Title: Re: Moving many files up one directory level
Post by: Geek-9pm on January 11, 2010, 08:42:42 PM
Now that we have all confused him,
If his file structure is in good shape ...
and if explorer is not bite by bugs.

He can do it in one drop and drag.
Title: Re: Moving many files up one directory level
Post by: BC_Programmer on January 11, 2010, 09:44:39 PM
Now that we have all confused him,
If his file structure is in good shape ...
and if explorer is not bite by bugs.

He can do it in one drop and drag.


No. he can't. you might want to read a bit closer.

He wants to move the files in all the DIFFERENT level3 folders beneath the level 2 folders into the respective level 2 folders. THIS CANNOT be done quickly with explorer.
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 12, 2010, 12:10:39 AM
Ahh, OK, guess I misunderstood :)

Code: [Select]
@echo off
for /f %%P in ('dir /b /od') do copy %%P\level3\*.*  .\%%P\
REM for /f %%P in (dir /b /od') do rmdir /s /q %%P\level3

Run this from within your "level1" folder. it will do something similar to the previous batch I provided; this one loops through all the folders ('dir /b /od') and copies the files from within the level3 folder of that folder "out" of the folder into the "level2" folder that it's looping through.

Again, the remarked out rmdir command will remove the level3 folders, as well. the first loop only copies. and change the "%%P\level3\*.*" to "%%P\level3\*.mp3" to only copy mp3 files. (as I'm sure your aware deleting the folder will result in the loss of other files that are not MP3 from within that folder.

Hey, I am pretty sure this will work, except I may not have given you all the required info.

"Level 1" is always called "music" but the "Level 2" and "Level 3" directories always have different names. In that BAT file you gave me I noticed that you you have a couple of commands which point specifically to folders called "Level 3": is there a way to just point to directories at this level in the tree rather than folders actually named "Level 3"?

Thanks so much!
Title: Re: Moving many files up one directory level
Post by: Salmon Trout on January 12, 2010, 12:16:29 AM
Code: [Select]
@echo off
cd "C:\Documents and Settings\cameronyoung\Level1\Level2\Level3\"

copy *.mp3  "C:\Documents and Settings\cameronyoung\Level1\Level2\"

delete *.*
 


 ::)
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 12, 2010, 12:18:14 AM
::)
Sorry you haven't read my post properly. BC_Programmer could you please check my reply? Thanks heaps.
Title: Re: Moving many files up one directory level
Post by: Salmon Trout on January 12, 2010, 12:33:28 AM
Sorry you haven't read my post properly. BC_Programmer could you please check my reply? Thanks heaps.

I have, somebody else hasn't.
Title: Re: Moving many files up one directory level
Post by: BC_Programmer on January 12, 2010, 01:57:14 AM
Original code:

Code: [Select]
@echo off
for /f %%P in ('dir /b /od') do (
    pushd %%P
    for /f %%I in ('dir /b /od') do (
        copy "%%P\%%I\*.*"  ".\%%P\"
        REM rmdir /s /q "%%P\%%I"
    )
    popd

)


new code:

Code: [Select]
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "usebackq delims=" %%P in (`dir /b /ad`) do (
    pushd %%P
    for /f "usebackq delims=" %%I in (`dir /b /ad`) do (
         copy "%%I\*.*"  .\
         REM rd /s /q "%%I"
    )
    popd

)

changed the dir command to what I originally intended; I had /od, but /o and -o are for sorting. changed it to /ad so they would both only enumerate directories.

Given the new requirements, added a nested loop within the original, to account for "level3" folders having different names. In this case, it iterates on ALL folders within each folder; Again, I have the rd command remmed out here; unrem it after you test it for it to delete the folders as you wanted. It worked for my tests (it moved all data in third level folders to their respective second level folders) however, with multiple folders we have the problem of duplicate filenames in these folders; copy will prompt to overwrite in this scenario.
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 28, 2010, 08:19:43 PM
Hey BC_Programmer,

I added the below code to a .BAT file but it didn't work.

Code: [Select]
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "usebackq delims=" %%P in (`dir /b /ad`) do (
    pushd %%P
    for /f "usebackq delims=" %%I in (`dir /b /ad`) do (
         copy "%%I\*.*"  .\
         REM rd /s /q "%%I"
    )
    popd

)

When I added the code as is, it didn't move any files or delete anything.  When I removed the REM it just deleted everything except the parent directories.

Am I doing something wrong?  I ran the .BAT file from "S:\MUSIC\test.bat" and these are the exact files I had in the directory:

S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\dalek vs faust v0\01 jhevevevj.mp3
S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\dalek vs faust v0\02 83fjh3v3v.mp3
S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\dalek vs faust v0\03 jeje vv urvfrv.mp3
S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\dalek vs faust v0\folder.jpg
S:\MUSIC\mazzy star\1991 - she hangs brightly\she hangs brightly\01 whh whh whaaamp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\she hangs brightly\02 bleeef dikee aa.mp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\she hangs brightly\03 !.mp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\she hangs brightly\playlist.m3u

I had hoped that it would produce the following:

S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\01 jhevevevj.mp3
S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\02 83fjh3v3v.mp3
S:\MUSIC\dalek vs faust\2004 - derbe respect, alder\03 jeje vv urvfrv.mp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\01 whh whh whaaamp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\02 bleeef dikee aa.mp3
S:\MUSIC\mazzy star\1991 - she hangs brightly\03 !.mp3

Ideally I would have liked it to move only the .MP3 files and then for it to remove the directories the MP3s were moved from and any non-MP3 files they contain.

It needs to be something generic though, as there are about 2000 more "dalek vs faust" and "mazzy star" level directories with the exact same structure.

Please let me know if this isn't clear.  Thank you.
Title: Re: Moving many files up one directory level
Post by: Salmon Trout on January 29, 2010, 12:16:28 AM
Sorry to jump in, but shouldn't this

copy "%%I\*.*"  .\

be this

copy "%%I\*.*"  ..\

?

(i.e. two dots refer to the next folder up)

Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 29, 2010, 12:21:02 AM
Hi Salmon,

Possibly, but that still doesn't do anything, unless I remove the "REM", in which case it deletes everything and just leaves me with two empty directories:

S:\MUSIC\dalek vs faust\
S:\MUSIC\mazzy star\

I'm running it from S:\MUSIC\test.bat.

Hope you can help. Thanks.
Title: Re: Moving many files up one directory level
Post by: oldun on January 29, 2010, 01:51:36 PM
It may be easier to use VBScript.
Title: Re: Moving many files up one directory level
Post by: Salmon Trout on January 29, 2010, 02:07:44 PM
It may be easier to use VBScript.

O ye of little faith...

Code: [Select]
@echo off
set thisdir=%cd%
for /f "delims=" %%A in ('dir /b /ad') do (
    cd /d "%%~dpnA"
    for /f "delims=" %%B in ('dir /b /ad') do (
         echo Level 2 Directory: %%~dpnB
         cd /d "%%~dpnB"
         for /f "delims=" %%C in ('dir /b /ad') do (
          echo Level 3 Directory: %%~dpnC
          cd /d "%%~dpnC"
          move *.mp3 ..\
          cd..
          rd "%%~dpnC"
         )
    )
)
cd /d "%thisdir%

Run in S:\Music

Before...

Code: [Select]
S:\music>dir /b /s /a-d
S:\music\subtest.bat
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\01 - Hope There's Someone.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\02 - My Lady Story.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\03 - For Today I Am A Boy.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\04 - Man Is The Baby.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\05 - You Are My Sister.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\06 - What Can I Do.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\07 - Fistfull Of Love.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\08 - Spiralling.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\09 - Free At Last.mp3
S:\music\Test\Antony and the Johnsons\I Am A Bird Now\10 - Bird Guhl.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\01 - i fell in love with a dead boy.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\02 - mysteries of love.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\03 - hitler in my heart.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\04 - atrocities.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\05 - river of sorrow.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\06 - rapture.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\07 - deeper than love.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\08 - divine.mp3
S:\music\Test\Antony and the Johnsons\Selftitled\09 - blue angel.mp3

After...

Code: [Select]
S:\music>dir /b /s /a-d
S:\music\subtest.bat
S:\music\Test\Antony and the Johnsons\01 - Hope There's Someone.mp3
S:\music\Test\Antony and the Johnsons\01 - i fell in love with a dead boy.mp3
S:\music\Test\Antony and the Johnsons\02 - My Lady Story.mp3
S:\music\Test\Antony and the Johnsons\02 - mysteries of love.mp3
S:\music\Test\Antony and the Johnsons\03 - For Today I Am A Boy.mp3
S:\music\Test\Antony and the Johnsons\03 - hitler in my heart.mp3
S:\music\Test\Antony and the Johnsons\04 - atrocities.mp3
S:\music\Test\Antony and the Johnsons\04 - Man Is The Baby.mp3
S:\music\Test\Antony and the Johnsons\05 - river of sorrow.mp3
S:\music\Test\Antony and the Johnsons\05 - You Are My Sister.mp3
S:\music\Test\Antony and the Johnsons\06 - rapture.mp3
S:\music\Test\Antony and the Johnsons\06 - What Can I Do.mp3
S:\music\Test\Antony and the Johnsons\07 - deeper than love.mp3
S:\music\Test\Antony and the Johnsons\07 - Fistfull Of Love.mp3
S:\music\Test\Antony and the Johnsons\08 - divine.mp3
S:\music\Test\Antony and the Johnsons\08 - Spiralling.mp3
S:\music\Test\Antony and the Johnsons\09 - blue angel.mp3
S:\music\Test\Antony and the Johnsons\09 - Free At Last.mp3
S:\music\Test\Antony and the Johnsons\10 - Bird Guhl.mp3


Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 29, 2010, 05:14:45 PM
Hey Salmon!!

This doesn't seem to loop through the directories for me. It works on the first directory, and then says "The system cannot find the path specified." This is the output (sorry it's so long):

Code: [Select]
S:\music>dir /b /s /a-d
S:\music\subtest.bat
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\01 - fleetwo
od mac - big love.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\02 - fleetwo
od mac - seven wonders.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\03 - fleetwo
od mac - everywhere.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\04 - fleetwo
od mac - caroline.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\05 - fleetwo
od mac - tango in the night.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\06 - fleetwo
od mac - mystified.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\07 - fleetwo
od mac - little lies.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\08 - fleetwo
od mac - family man.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\09 - fleetwo
od mac - welcome to the room...sara.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\10 - fleetwo
od mac - isn't it midnight.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\11 - fleetwo
od mac - when i see you again.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\12 - fleetwo
od mac - you and i, part ii.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
1-skies the limit.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
2-love is dangerous.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
3-in the back of my mind.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
4-do you know.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
5-save me.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
6-affairs of the heart.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
7-when the sun goes down.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
8-behind the mask.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
9-stand on the rock.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
0-hard feelings.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
1-freedom.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
2-when it comes to love.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
3-the second time.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
1 - talkin' to my heart.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
2 - hollywood (some other kind of town).mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
3 - blow by blow.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
4 - winds of change.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
5 - i do.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
6 - nothing without you.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
7 - dreamin' the dream.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
8 - sooner or later.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
9 - i wonder why.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
0 - nights in estoril.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
1 - i got it for you.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
2 - all over again.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
3 - these strange times.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-01 what's the world coming to.mp
3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-02 murrow turning over in his gr
ave.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-03 illume (9-11).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-04 thrown down.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-05 miranda.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-06 red rover.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-07 say you will.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-08 peacekeeper.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-09 come.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-10 smile at you.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-11 running through the garden.mp
3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-12 silver girl.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-13 steal your heart away.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-14 bleed to love her.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-15 everybody finds out.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-16 destiny rules.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-17 say goodbye.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-18 goodbye baby.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-01 love minus zero_no limit (liv
e version).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-02 not make believe (live versio
n).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-03 peacekeeper (live from aol se
ssions).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-04 say you will (live from aol s
essions).mp3

S:\music>subtest.bat
Level 2 Directory: S:\music\fleetwood mac\1987 - tango in the night
Level 3 Directory: S:\music\fleetwood mac\1987 - tango in the night\tango in the
 night
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\01 - fleetwo
od mac - big love.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\02 - fleetwo
od mac - seven wonders.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\03 - fleetwo
od mac - everywhere.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\04 - fleetwo
od mac - caroline.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\05 - fleetwo
od mac - tango in the night.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\06 - fleetwo
od mac - mystified.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\07 - fleetwo
od mac - little lies.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\08 - fleetwo
od mac - family man.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\09 - fleetwo
od mac - welcome to the room...sara.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\10 - fleetwo
od mac - isn't it midnight.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\11 - fleetwo
od mac - when i see you again.mp3
S:\music\fleetwood mac\1987 - tango in the night\tango in the night\12 - fleetwo
od mac - you and i, part ii.mp3
       12 file(s) moved.
Level 2 Directory: S:\music\fleetwood mac\1987 - tango in the night\1990 - behin
d the mask
The system cannot find the path specified.
Level 2 Directory: S:\music\fleetwood mac\1987 - tango in the night\1995 - time
The system cannot find the path specified.
Level 2 Directory: S:\music\fleetwood mac\1987 - tango in the night\2003 - say y
ou will
The system cannot find the path specified.

S:\music>dir /b /s /a-d
S:\music\subtest.bat
S:\music\fleetwood mac\1987 - tango in the night\01 - fleetwood mac - big love.m
p3
S:\music\fleetwood mac\1987 - tango in the night\02 - fleetwood mac - seven wond
ers.mp3
S:\music\fleetwood mac\1987 - tango in the night\03 - fleetwood mac - everywhere
.mp3
S:\music\fleetwood mac\1987 - tango in the night\04 - fleetwood mac - caroline.m
p3
S:\music\fleetwood mac\1987 - tango in the night\05 - fleetwood mac - tango in t
he night.mp3
S:\music\fleetwood mac\1987 - tango in the night\06 - fleetwood mac - mystified.
mp3
S:\music\fleetwood mac\1987 - tango in the night\07 - fleetwood mac - little lie
s.mp3
S:\music\fleetwood mac\1987 - tango in the night\08 - fleetwood mac - family man
.mp3
S:\music\fleetwood mac\1987 - tango in the night\09 - fleetwood mac - welcome to
 the room...sara.mp3
S:\music\fleetwood mac\1987 - tango in the night\10 - fleetwood mac - isn't it m
idnight.mp3
S:\music\fleetwood mac\1987 - tango in the night\11 - fleetwood mac - when i see
 you again.mp3
S:\music\fleetwood mac\1987 - tango in the night\12 - fleetwood mac - you and i,
 part ii.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
1-skies the limit.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
2-love is dangerous.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
3-in the back of my mind.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
4-do you know.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
5-save me.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
6-affairs of the heart.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
7-when the sun goes down.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
8-behind the mask.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\0
9-stand on the rock.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
0-hard feelings.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
1-freedom.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
2-when it comes to love.mp3
S:\music\fleetwood mac\1990 - behind the mask\fleetwood mac behind the mask v0\1
3-the second time.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
1 - talkin' to my heart.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
2 - hollywood (some other kind of town).mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
3 - blow by blow.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
4 - winds of change.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
5 - i do.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
6 - nothing without you.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
7 - dreamin' the dream.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
8 - sooner or later.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 0
9 - i wonder why.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
0 - nights in estoril.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
1 - i got it for you.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
2 - all over again.mp3
S:\music\fleetwood mac\1995 - time\fleetwood mac - time (1995)\fleetwood mac - 1
3 - these strange times.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-01 what's the world coming to.mp
3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-02 murrow turning over in his gr
ave.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-03 illume (9-11).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-04 thrown down.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-05 miranda.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-06 red rover.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-07 say you will.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-08 peacekeeper.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-09 come.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-10 smile at you.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-11 running through the garden.mp
3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-12 silver girl.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-13 steal your heart away.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-14 bleed to love her.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-15 everybody finds out.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-16 destiny rules.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-17 say goodbye.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 1)\1-18 goodbye baby.mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-01 love minus zero_no limit (liv
e version).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-02 not make believe (live versio
n).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-03 peacekeeper (live from aol se
ssions).mp3
S:\music\fleetwood mac\2003 - say you will\fleetwood mac - say you will - ltd ed
ition\say you will (limited edition - disc 2)\2-04 say you will (live from aol s
essions).mp3

S:\music>

Also, I noticed if there are non MP3 files in the directory from which the MP3s are moved, the directory won't be deleted? Is it possible to make it delete the directory and any non-MP3 files?

Thank you so much!!
Title: Re: Moving many files up one directory level
Post by: oldun on January 30, 2010, 08:47:05 PM
O ye of little faith...
It's not so much "little faith" as limited knowledge/experience with batch scripts.  :-[

This VBScript code might (hopefully) work.

Code: [Select]
Option Explicit
Dim base,ext,debug,dest,oShell,fso,olog
Dim i,oExec,oOut,fldrs,j,fls,k,ret,f2del
' ****************************
' AMEND AS NECESSARY
base="S:\MUSIC" '<- CHANGE THIS TO THE BASE FOLDER
ext=".mp3" '<- CHANGE THIS TO THE REQUIRED EXTENSION
' CHANGE THE DEBUG VALUE TO 0 TO PERFORM THE ACTIONS
' When debug=1, a log file (MoveUp.log) will be created.
' Verify that everything appears OK, then change this value
' to 0, and run the script to actually move the files and
' delete the remaining folders.
debug=1 '<- CHANGE THIS TO 0 IF ALL APPEARS OK
' ****************************
If Right(base,1)="\" Then
base=Left(base,Len(base) -1)
End If
If Left(ext,1)<>"." Then
ext="." & ext
End If
dest=Split(getDestFldrs(base),vbCrLf)
Set oShell=CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
Set olog=fso.CreateTextFile(Left(WScript.ScriptFullName, _
Len(WScript.ScriptFullName) -3) & "Log", True)
If debug then
olog.WriteLine("Destination Folders:")
For i=0 To UBound(dest) -1
olog.WriteLine(dest(i))
Next
olog.WriteLine()
End If
For i=0 To UBound(dest) -1
Set oExec=oShell.Exec("Cmd /C Dir /S /B /AD " & Chr(34) & dest(i) & Chr(34))
Set oOut=oExec.StdOut
fldrs=Split(oOut.ReadAll,vbCrLf)
If UBound(fldrs)>0 Then
If debug Then
olog.WriteLine("The following files will be moved to:")
olog.WriteLine(dest(i)&vbCrLf)
End If
End If
For j=0 To UBound(fldrs) -1
If debug Then
Set oExec=oShell.Exec("Cmd /C Dir /B " & Chr(34) & fldrs(j) & "\*" & ext & Chr(34))
Set oOut=oExec.StdOut
fls=Split(oOut.ReadAll,vbCrLf)
For k=0 To UBound(fls) -1
olog.WriteLine(fldrs(j) & "\" & fls(k))
Next
Else
ret=oShell.Run("Cmd /C Move /Y " & Chr(34) & fldrs(j) & "\*" & ext & Chr(34) & " " & Chr(34) & dest(i) & "\" & Chr(34),0,True)
If ret then
WScript.Echo "ERROR! MOVING FILES"
End If
End If
Next
Set oExec=oShell.Exec("Cmd /C Dir /B /AD " & Chr(34) & dest(i) & Chr(34))
Set oOut=oExec.StdOut
f2del=Split(oOut.ReadAll, vbCrLf)
If debug Then
If UBound(f2del)>0 Then
olog.WriteLine(vbCrLf & "The following directories (and subdirectories), below the folder:" & vbCrLf & dest(i) & vbCrLf & "will be removed:")
End If
End If
For j=0 To UBound(f2del) -1
If debug Then
olog.WriteLine(f2del(j))
Else
ret=oshell.Run("Cmd /C RD /Q /S " & Chr(34) & dest(i) & "\" & f2del(j) & Chr(34),0,True)
If ret Then
Wscript.Echo "ERROR! REMOVING FOLDER"
End If
End If
Next
olog.WriteLine()
Next
WScript.echo "Done!"
' ***** END OF SCRIPT *****
Function getDestFldrs(sPath)
Dim fso, fldr, sFldr, dest
dest=""
Set fso=WScript.CreateObject("Scripting.FileSystemObject")
With fso.GetFolder(sPath)
If .SubFolders.Count>0 Then
For Each fldr In .SubFolders
With fso.GetFolder(fso.BuildPath(sPath, fldr.Name))
If .SubFolders.Count>0 Then
For Each sFldr In .SubFolders
dest=dest & fso.BuildPath(fso.BuildPath(sPath,fldr.Name),sfldr.Name) & vbCrLf
Next
End If
End With
Next
End If
End With
getDestFldrs=dest
End Function
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 31, 2010, 02:26:04 AM
Thanks Olden, but how do I create a VBScript? In Excel? Sorry.
Title: Re: Moving many files up one directory level
Post by: Salmon Trout on January 31, 2010, 02:39:33 AM
Hey Salmon!!

This doesn't seem to loop through the directories for me. It works on the first directory, and then says "The system cannot find the path specified."

That is because, to get the required folder depth shown in your first post, you should have run it in S:\Music\Fleetwood Mac, not S:\Music as your post shows. Your example in your first post has one less folder level than your Fleetwood Mac setup.

Title: Re: Moving many files up one directory level
Post by: oldun on January 31, 2010, 02:43:39 AM
Copy and paste the code into Notepad, and save the file anywhere on your hard disk, using any name you like (I used MoveUp), but make sure that you save it with an extension of .VBS

Then open a command prompt window and run it the same way as a .CMD or .BAT file. i.e. type the filename in the command shell and press enter.
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 31, 2010, 04:06:15 AM
OLDUN!!!!!!!!!!!!!!!!!!!!!!! AWESOME!!!!!!!!!!!!!!!!!!!!!!!!


THANK YOU SOOOOO MUCH!!!!!!!!!!  YOU ARE GOING TO SAVE MY *SO MUCH* TIME!!!!


Without being rude, could I ask if it would be very difficult to alter the script slightly so that it did exactly what it did now except instead of moving files "up one directory" it moved all the files to the Nth directory.

I.E. so that say you had:

S:\music\fleetwood mac\1987 - tango in the night\tango in the night (v0)\disk 1\*.mp3 --> i.e. 5 dirs
S:\music\fleetwood mac\1987 - tango in the night\tango in the night (v0)\disk 2\*.mp3 --> i.e. 5 dirs
S:\music\fleetwood mac\1990 - behind the mask\behind the mask (v0)\*.mp3 --> i.e. 4 dirs
S:\music\fleetwood mac\1995 - time\time (v0)\*.mp3 --> i.e. 4 dirs
S:\music\fleetwood mac\2003 - say you will\*.mp3 --> i.e. 3 dirs

Could you make it so that it did everything it did now but just moved them to like the 3rd directory level? So that you ended up with:

S:\music\fleetwood mac\1987 - tango in the night\*.mp3 --> i.e. 3 dirs
S:\music\fleetwood mac\1987 - tango in the night\*.mp3 --> i.e. 3 dirs
S:\music\fleetwood mac\1990 - behind the mask\*.mp3 --> i.e. 3 dirs
S:\music\fleetwood mac\1995 - time\*.mp3 --> i.e. 3 dirs
S:\music\fleetwood mac\2003 - say you will\*.mp3 --> i.e. 3 dirs


Is that something VBScript can do?  THANK YOU SO MUCH!!! DON'T WORRY IF IT'S A BIG DEAL!!!!!
Title: Re: Moving many files up one directory level
Post by: oldun on January 31, 2010, 04:20:33 AM
That's what it should be doing.

If it doesn't, set the "debug" line to 1, and post a portion of the output to show where it's going wrong.

It's late here, so I may not look at it until tomorrow.
Title: Re: Moving many files up one directory level
Post by: cameronyoung on January 31, 2010, 04:24:37 AM
You're totally right that's even better!!!!!!!!!!  THANK YOU AGAIN!!!!!!!


[SOLVED]
Title: Re: Moving many files up one directory level
Post by: oldun on January 31, 2010, 04:41:37 AM
You are welcome. Glad I was able to help.
Title: Re: Moving many files up one directory level
Post by: Chanimal on February 07, 2010, 10:20:41 AM
HELP!!

Oldun,

I want to do something like Cameron's request, but a little different.......

I have this directory that I use to store all my media for itunes, I call is the (Music)M:

In there, itunes has organized it through Artist\Album\Title.mp3

I want to so a wholesale clean up of each Title.mp3's naming structure as well as ID3 tags

To begin this, I want to extract every .mp3 file out of each and every folders in all the levels of filing up to the root M:\ level.

I tried running that VBS script you posted earlier, it didn't work.  It kicked out some line 82 character 2 error.  Do I have to save it to the M:\, and then use Start --> Run to run it in M:\ to have it work?  I suspect the script you wrote does not strip the filing levels to the root level, as Cameron did not ask for that.

Would you mind dispensing some advice my way?
Title: Re: Moving many files up one directory level
Post by: oldun on February 07, 2010, 05:31:00 PM
I tried running that VBS script you posted earlier, it didn't work.

This script was written to perform a very specific set of actions. It is not a generic "file move" script, so it is not surprising that it didn't work.

Please explain exactly what you are trying to achieve, preferably by showing some examples, and I or someone else on this forum will try to help, if we can.

By the way, you should start a new thread, and not hijack someone else's post.