'Dissolve' Folders

Soldato
Joined
23 Mar 2005
Posts
3,887
I'm currently dreading a tidy-up job that I have to do. I have to ensure that there are no folders beyond a certain level on our system. At the moment that means going through with explorer and manually moving files from folders beyond this tier into the it and deleting the then empty folders. (ie. C: - Folder - Folder - Folder - Files: No files in the folder levels, no folders in or beyond the File level :mad:)

Instead of doing it by hand is there a simple command to 'dissolve' all of the offending folders and leave their contents in the base folder? Bearing in mind I won't be able to install any 3rd party software it has to be something built into XP (or cmd)?
 
I found a handy script that does some of this Here:

Set _Source=%*
For %%I in (%_Source%) Do (
For /F "usebackq tokens=*" %%J In (`DIR /B /AD "%_Source%"`) Do Move /-Y "%%~I\%%J" "%%~dpI"
Move /-Y "%%~I\*.*" "%%~dpI"
RD "%%~I"
)
::pause

Works well for a single level, but doesn't go up the tree for further folders - anyone know how to amend this to do all directories above the current level?
 
Are you able to install Microsoft Tools? If so get yourself Powershell. I think I may be able to write something later that can do what you want.

My batch scripting isn't good enough to modify the beast cavemanoc posted.
 
Probably not - the system is almost entirely locked down - IIRC even the CD drives are disabled now :rolleyes: If it doesn't come as standard in an XP install we won't have it.
 
Ahh that sucks.

Well, if I have a chance I will see if I can modify that batch script. I wouldn't hold your breath though! :p
 
cheers for that - it sounds like a pretty complex if statement to achieve what I'm after - will also dig about in the batch tutorials to see if I can find a way around it
 
Maybe try a multi-step thing, like this (written from top of head, and not tested!)


dir "C:\Path\" /s /b *.* > list.txt

Open list.txt in Notepad.

Add to the beginning of each line:

Find & Replace:
C:\Path\

with

move "C:\Path\

and add to the end of each line:

" C:\

Save as something.bat, and run it.

(If it's a specific file-type, for example they're all ".pdf"s, then you can do a find/replace on the end of each line from

.pdf

to

.pdf" C:\
 
Having a little play now - not sure if it's Windows 7 specific (hope not!) but I've been able to simplify the first part a bit. Ensuring I'm in the base directory (c:\level1) I used:

dir /s /b > list.txt

Didn't seem to need any of the quotations or the 'all' option (*.*) - I like the > command - never knew that (embarrassing considering how many batch files I've written over the years!)

Hmmm... The last bit isn't really going to cut it - unfortunately I will end up with hundreds of lines, at the end of which I'll have to manually add in the destination (C:\ - or in the real case something far more complex) It would be too labour intensive, and I'd actually be quicker simply moving the files by hand :(

Also begs the question, what happens to the directories that get moved down? That bit I'm going to try just to see what happens!

Oooo - Looks like the forfiles command may be the answer - just refining, but from another forum something like:

forfiles /s /m *.* /p [path-to-mp3-files] /c "cmd /c move @file [destination-dir]
-Just need to play with the switches to make sure it takes all files from all subdirectories...
 
Last edited:
Done!! :D

In the c:\level1 directory I use:

forfiles /s /m *.* /c "cmd /c move @file c:\level1"

And it worked - sweet - :eek: Shocked - now lets see if it works for real...

(I did have a moment of pause as I did this on the laptop - one level up from the root in the C: drive - wondering what it would look like if it went wrong and moved ALL files on the drive into c:\...:eek:)

Edit: One last add on at this stage - I'm pretty sure that cmd.exe has been disabled fairly robustly on the system so I won't be able to go to the command line directly, plus the folders are all on a network drive which I probably wouldn't be able to find :rolleyes: so I have used the "send to" trick and written the command above into a batch file. The advantage of this is that I can quickly work through the directories with 'right-click'! I tried it on mine (Windows 7) and fell into the Admin Privilege trap - which was annoying - I can't elevate the batch file to 'run as administrator' so all of the moves come back as 'access denied' :( - but it's doing the right thing which fills me with hope - XP doesn't have these issues so I think I'm there! Will try it today and see how it goes.
 
Last edited:
Disaster - access to cmd.exe has been closed - so I just get an access denied message when I run the batch :mad: Is there any way to run something similar but in windows without recourse to cmd.exe?
 
cmd just opens a prompt. You should be able to run each command individually from a Run box.

If you've never known about the > operator, then another gem of knowledge is that >> will do the same, but will append to the existing file.

You're welcome :D
 
Thanks indeed for the >>

As I see it the forfiles command only works with the "move" command if you use the cmd /c (as per the syntax explanation for the command) - bearing in mind I want to right click on a folder and 'run' may batch file on it (hence the 'Send To' trick) I'm not sure how I can get around the involvement of cmd.exe :confused:

What I need is a script that does what the forfiles command does in a dosbox - but in Windows proper - something like the original script near the top, but with the simplified effect of the forfiles batch - I'm sure there's a really simple way of doing it...
 
Last edited:
Back
Top Bottom