Page 1 of 1

batch file that cleans desktop?

Posted: 13 Jun 2011 14:32
by CatIntheBox
Hello, im trying to make an not rly common thing lol, i need to remove all the desktop icons and folders with the subfolders ofcourse in to a specific folder. i wanna do all this with a single silent batch file :)
here is what i came up with:

Code: Select all

@echo off
xcopy /Y %userprofile%\Desktop\*.* %userprofile%\DesktopFiles\  /s /q /f
del %userprofile%\Desktop\*.* /s /q /f
ECHO Y | RD /s %userprofile%\Desktop\


im sure my code is wrong, and also because the thing what happens, it does moves the files but it leaves all the empty folders on the desktop. i know that the RD command also trys to delete "desktop" folder with all the subfolders, but since desktop folder is busy and cant be deleted, then this whole thing just fails and none of the folders gets deleted. well i know that the RD now stands in fail, but i cant figure out anything better :/ please help and rewrite my commands in right way to get to the goal ;D

Re: batch file that cleans desktop?

Posted: 14 Jun 2011 02:52
by CatIntheBox
newermind, i figured out myself.. it works now like a charm. if anyone needs this desktop .bat for some reason, pm me :)

Re: batch file that cleans desktop?

Posted: 20 Jun 2011 12:48
by avtarsingh17
would you mind sharing the code??
I have a similar requirement where I need to clean all files/folders from desktop.

Re: batch file that cleans desktop?

Posted: 20 Jun 2011 14:42
by nitt
All you want to do is delete all files, folders, and subfolders in a directory? That's like super easy...

Code: Select all

for /f "tokens=*" %%a in ('dir /b') do (if "%%a" NEQ "file.bat" (echo y|del "%%a" & echo y|rmdir /s /q "%%a"))


For the "NEQ "file.bat"" part, that assumes that the Batch file's name is "file.bat". If it had a different name just change that. I put in that to make sure it doesn't delete itself.

Re: batch file that cleans desktop?

Posted: 24 Jun 2011 05:07
by orange_batch
^ Careful, nitt's code assumes you only want to delete everything (including folders) on the desktop, not move or copy it beforehand.

On that note, why are you copying instead of moving, CatInTheBox? It would be infinitely faster if you just move the files instead of copying then deleting them.

Re: batch file that cleans desktop?

Posted: 24 Jun 2011 17:03
by scienceguru1.bat
if you put nitt's code after the origional code, it should work fine - if you have the batch file in a different folder. also, he is moving - xcopy is the command for move.

Re: batch file that cleans desktop?

Posted: 25 Jun 2011 00:35
by orange_batch
Uhm, move is the command for move. Xcopy is another command for copy. 8)

If you're moving to the same drive, the data doesn't need to be rewritten, just the virtual location = way faster.

Re: batch file that cleans desktop?

Posted: 25 Jun 2011 04:32
by Cleptography
rundll32.exe fldrclnr.dll,Wizard_RunDLL all