Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Merge contents of subfolders into a single folder

Posted on 2004-11-18
6
Medium Priority
?
1,103 Views
Last Modified: 2012-06-21
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!  
0
Comment
Question by:tomfolinsbee
  • 3
  • 2
6 Comments
 
LVL 97

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 500 total points
ID: 12616060
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
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12617601
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
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12617619
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 2

Assisted Solution

by:nevahj
nevahj earned 500 total points
ID: 12796864

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
 
LVL 2

Expert Comment

by:nevahj
ID: 12796889

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
 
LVL 9

Accepted Solution

by:
DrWarezz earned 1000 total points
ID: 12952206
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

810 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