batch file that cleans desktop?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CatIntheBox
Posts: 2
Joined: 13 Jun 2011 12:00

batch file that cleans desktop?

#1 Post by CatIntheBox » 13 Jun 2011 14:32

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

CatIntheBox
Posts: 2
Joined: 13 Jun 2011 12:00

Re: batch file that cleans desktop?

#2 Post by CatIntheBox » 14 Jun 2011 02:52

newermind, i figured out myself.. it works now like a charm. if anyone needs this desktop .bat for some reason, pm me :)

avtarsingh17
Posts: 1
Joined: 20 Jun 2011 12:45

Re: batch file that cleans desktop?

#3 Post by avtarsingh17 » 20 Jun 2011 12:48

would you mind sharing the code??
I have a similar requirement where I need to clean all files/folders from desktop.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: batch file that cleans desktop?

#4 Post by nitt » 20 Jun 2011 14:42

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.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: batch file that cleans desktop?

#5 Post by orange_batch » 24 Jun 2011 05:07

^ 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.

scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: batch file that cleans desktop?

#6 Post by scienceguru1.bat » 24 Jun 2011 17:03

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.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: batch file that cleans desktop?

#7 Post by orange_batch » 25 Jun 2011 00:35

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.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: batch file that cleans desktop?

#8 Post by Cleptography » 25 Jun 2011 04:32

rundll32.exe fldrclnr.dll,Wizard_RunDLL all

Post Reply