Solved

I need to batch move folders up one level

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

20 Experts available now in Live!

Get 1:1 Help Now