Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I need to batch move folders up one level

Posted on 2014-04-24
2
Medium Priority
?
1,318 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 85

Accepted Solution

by:
oBdA earned 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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…
Introduction to Processes

664 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