DOS - Empty a Directory

Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0
I've been searching around for a while.. looking for a DOS command to delete all files and folders within the specified directory, without deleting that specified directory.
 
xD Here's my dilemma, the folder can't be deleted or moved, at all.. I somehow need to move everything (all files and folders) within that folder to another folder. I figured I'd copy the folder to the other location and then delete everything in the original folder... but deleting everything in that folder without deleting the folder itself seems to not be so simple.
 
Well are we talking about DOS or command prompt here in the first place? It sounds like you get an error in windows when you try to remove a directory saying it's in use, but nothing to the best of your knowledge uses it. Perhaps try rebooting to safe mode, less stuff loaded there and you might get to remove it. On the other hand, if it works then you might still have to deal with windows bitching about the folder missing afterwards... <.<
 
You obviously can't search, or you were too lazy to read through the command reference -.-

MS-DOS deltree command help

Deletes a directory and all the subdirectories and files in it. I obviously did read it, and unlike you, realized it didn't fit my situation.

I guess it's not actually DOS, my bad. What I am trying to do is make a batch file that moves everything from my desktop (all folders and files) to another folder on my desktop, then moves all .lnk files from that folder back onto the desktop.. a little cleanup tool.

I tried doing it like this:
Code:
move "C:\Documents and Settings\Owner\Desktop\*.*" "C:\Documents and Settings\Owner\Desktop\unsorted"
move "C:\Documents and Settings\Owner\Desktop\Unsorted" C:\Unsorted
move "C:\Documents and Settings\Owner\Desktop" C:\unsorted
md "C:\Documents and Settings\Owner\Desktop"
move C:\unsorted "C:\Documents and Settings\Owner\Desktop\unsorted"
move "C:\Documents and Settings\Owner\Desktop\unsorted\*.lnk" "C:\Documents and Settings\Owner\Desktop"
pause

I can't change C:\documents and settings\owner\desktop to C:\unsorted, which should have moved all the folders on the desktop to the unsorted folder, since folders would be the only thing left on the desktop at that time.

Since I can't move or delete the desktop folder, I figured I'd use xcopy to copy the desktop to the unsorted folder, then empty out the desktop. All I need is a way of deleting every subdirectory within a directory without deleting that directory itself.

If there isn't a way to do this, I guess I'll try Windows PowerShell.

It'd be nice if I could do something like:
rmdir "C:\Documents and Settings\Owner\Desktop\*"
 
It is challenging to understand what you mean and I actually still don't but perhaps any of the following can be of use.

But if I understand you're trying to remove your desktop folder? Which will not work, since its a system folder and is protected. The only way you can do such thing is login with a other account which is privileged to remove the folder (a administrator account).

As for the command to copy files

Copy files, including empty folder, sub folders and system files
xcopy "C:\Documents and Settings\Administrator\Desktop" C:\unsorted /S /E /C /H

(note that i used quotation around directory paths which included spaces)

Remember as a warning that xcopy has a limit on the number of files it can copy, it doesn't give a error it just stops as I had to find out in a less pretty experience. I believe the limit was 3000 files but it might have been 5000.
 
But if I understand you're trying to remove your desktop folder? Which will not work, since its a system folder and is protected. The only way you can do such thing is login with a other account which is privileged to remove the folder (a administrator account).

No, I'm trying to move or copy then delete all the folders on my desktop without moving or deleting my desktop folder. I could switch to another account to do it, but it'd be easier to just move the folders manually.. so that kinda defeats the purpose. I will do something like this as a last resort, but for now I'd like to try to find a way to move or delete all the folders within my desktop folder without moving or deleting the desktop folder itself.
 
Isn't manually moving so fast&easy you've already spent way more time typing than you'll ever spend with actually moving those files by hand?

Such a macro would treat the symptoms of your problem, but not cure the problem itself. You're certainly using your system in a very bad way if you need to clean up your desktop more often than once a month. Sounds like you use your desktop as the place to store everything you download.. to that I strongly advice checking your default paths for everything you do.

I know this all is avoiding your question, but the solution to that probably takes a little more advanced scripting tool and seems more difficult than changing the way you deal with your files in common use.
 
Isn't manually moving so fast&easy you've already spent way more time typing than you'll ever spend with actually moving those files by hand?

Such a macro would treat the symptoms of your problem, but not cure the problem itself. You're certainly using your system in a very bad way if you need to clean up your desktop more often than once a month. Sounds like you use your desktop as the place to store everything you download.. to that I strongly advice checking your default paths for everything you do.

I know this all is avoiding your question, but the solution to that probably takes a little more advanced scripting tool and seems more difficult than changing the way you deal with your files in common use.

Heh.. I knew someone would say that. I have no response on that matter, as it's my personal business. So I guess theres no way to do it the way I wanted... that sucks.. oh well.

Thanks for helping.
 
So I guess theres no way to do it the way I wanted
Sure there is. Pick a programming/scripting language, give it 5 minutes and there you have it. If you want to take this road but feel awkward with programming, get AutoIt. I always recommend it to anyone who needs to script anything from opening notepad to macroing actions in a game.. hell, I even made a lightweight hunting bot on it once.
 
Sure there is. Pick a programming/scripting language, give it 5 minutes and there you have it. If you want to take this road but feel awkward with programming, get AutoIt. I always recommend it to anyone who needs to script anything from opening notepad to macroing actions in a game.. hell, I even made a lightweight hunting bot on it once.

I think I'll just swallow my pride and move folders manually... :vegeta:
 
Back