Solved

I need to batch move folders up one level

Posted on 2014-04-24
2
1,201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
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…

733 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