Merge contents of subfolders into a single folder

How I can reduce this 3 level directory structure to a 2 level structure? The subfolders and files already have unique names. I just want to move subfolder11, subfolder12,.... subfolder 91, subfolder92, subfolder99 into a new folder called, let's say, NewFolder.

Current structure:
MainFolder
   Subfolder1
       Subfolder11
       Subfolder12
       Subfolder13 etc
   Subfolder2
        Subfolder21,
        Subfolder22
        Subfolder23 etc
   etc...
   Subfolder9
        Subfolder91
        Subfolder92
        Subfolder93 etc

New Structure:

NewFolder
   Subfolder11
   Subfolder12
   etc
   Subfolder93
   etc

Is there a DOS command that will do this?

Thank you!  
tomfolinsbeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
Try this:


---------------------------
@echo off
md ..\NewFolder
for /f "tokens=*" %%a in ('dir /ad /b') do (
cd %%a
for /f "tokens=*" %%m in ('dir /ad /b') do move .\%%m ..\..\NewFolder
cd ..
---------------------------
)
0
DrWarezzCommented:
OR:

:-----8<-------------------------- FileName.bat -----------------------------------------------:
@ECHO OFF

SET DirectoryToStart=c:\MainFolder
CD "%DirectoryToStart%"

SET DirToMoveTo=NewFolder
IF NOT EXIST "%DirToMoveTo%" MD "%DirToMoveTo%"

FOR /D /R %%D in (*) do (
    FOR /D %%A in (%%D\*) do MOVE "%%A" "%DirToMoveTo%" >>NUL
)
:-----8<-------------------------- FileName.bat -----------------------------------------------:

gL,
[r.D]
0
DrWarezzCommented:
Ah, change this:

FOR /D /R %%D in (*) do (
    FOR /D %%A in (%%D\*) do MOVE "%%A" "%DirToMoveTo%" >>NUL
)

to:

FOR /D %%D in (*) do (
    FOR /D %%A in (%%D\*) do MOVE "%%A" "%DirToMoveTo%" >>NUL
)
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

nevahjCommented:

Try VBScript - the following is a rough example of the MoveFolder method in WSH Script.

Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder("currentfolder\location\string")
Set colSubFolders = objFolder.SubFolders

For Each subfolder in colSubFolders
     subfolder.Move("newfolder\location\string") 'move file to a destinatin path
Next

HTH,
Charles

0
nevahjCommented:

Note you can nest this code:

Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder1 = fso.GetFolder("C:\Temp\Old")
Set colSubFolders1 = objFolder.SubFolders

For Each subfolder in colSubFolders1

      Set objFolder2 = fso.GetFolder(subfolder)
      Set colSubFolders2 = objFolder.SubFolders
      For Each subfolder in colSubFolders2
           subfolder.Move("C:\Temp\New")
      Next
Next

- Charles
0
DrWarezzCommented:
Tom,
does any of this help?

The last comment was posted more than 21 days ago. If you don't reply within the next 4 days, I will request that this thread is closed - with no points refunded.

[r.D]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.