Solved

I need to batch move folders up one level

Posted on 2014-04-24
2
1,129 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now