Solved

I need to batch move folders up one level

Posted on 2014-04-24
2
1,161 Views
Last Modified: 2014-04-24
I need to move folders & their contents (folders\files) up one level in Win Explorer:
Currently   D:\Music\<Performer>\<Composer>\<files> need to become
                  D:\Music\<Composer>\<files>
There can be one or more folders under each <Performer> folder, and these folder(s) may contain one or more files; there would be no duplication of folder names

I tried a script from a previous similar question (with the loc. edited):

@echo off
setlocal enabledelayedexpansion
set SourceFolder=C:\Temp\MyFiles
for /d %%a in ("%SourceFolder%\*.*") do (echo Processing '%%~nxa' ... for /d %%s in ("%%a\*.*") do (move "%%s" "%SourceFolder%")rd "%%a")

but it returned the error:  %%a was unexpected at this time

There are over 1000 folders involved - I really hope you can help

Cheers

If I delay in responding - it's 6pm. here now.
0
Comment
Question by:djwoody42
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40019437
The script should work just fine for you, but you need to save it as Whatever.cmd in the format listed below, not cobbled together like in your post. The script here is in test mode and will only display the "move" and "rd" commands it would normally run. Remove the uppercase ECHOs in lines 7 and 9 to run it for real.
@echo off
setlocal enabledelayedexpansion
set SourceFolder=D:\Music
for /d %%a in ("%SourceFolder%\*.*") do (
	echo Processing '%%~nxa' ...
	for /d %%s in ("%%a\*.*") do (
		ECHO move "%%s" "%SourceFolder%"
	)
	ECHO rd "%%a"
)

Open in new window

0
 

Author Closing Comment

by:djwoody42
ID: 40019776
Many thanks - you made my day.
I did have to do a search and delete a few thousand weird files (I didn't do the initial ripping - it was a gift) but the script them worked perfectly, including the folder deletions which had previously hung due to the above.
Thanks again.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question