Batch for cleaning folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Locutus
Posts: 2
Joined: 11 Sep 2013 06:49

Batch for cleaning folder

#1 Post by Locutus » 11 Sep 2013 07:27

Hey guys.

I would like to ask you to help me with one batchfile

I want to use a batch that runs including a timer of several seconds to clean some desktop files. Of course the sleep.exe is located in the same folder as the batchfile I want to run.

Unfortunately it doesn't want to work...

The code:
@echo off
echo Clean Desktop files...
sleep 20
del /f /s /q %userprofile%\Desktop\*.nal
del /f /s /q %userprofile%\Desktop\*.txt
echo. & pause


The error message is always: The system could not find the specified path - for both paths.

But with this (another) batch, it works all fine:
@echo off
echo Clean system temp files......
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\recent\*.*"
echo ²M°£¨t²Î©U§£§¹¦¨¡I
echo. & pause


I'm using WinXP professional, Service Pack 3.

Thanks in advance
Locutus

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch for cleaning folder

#2 Post by foxidrive » 11 Sep 2013 08:13

Double quotes protect batch paths and filenames from spaces and other poison characters, like &
Put them in all your "c:\paths\filenames"


Code: Select all

del /f /s /q "%userprofile%\Desktop\*.nal"
del /f /s /q "%userprofile%\Desktop\*.txt"

Locutus
Posts: 2
Joined: 11 Sep 2013 06:49

Re: Batch for cleaning folder

#3 Post by Locutus » 13 Sep 2013 06:14

Worked fine, thanks a lot!

Post Reply