Script to delete Temp folders in a click

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ahzong
Posts: 7
Joined: 04 Aug 2018 23:04

Script to delete Temp folders in a click

#1 Post by ahzong » 19 Aug 2018 08:37

Well actually, a double-click, on a batch script found online, as shown below:

Code: Select all

cd C:\Users\USER\Appdata\Local\Temp
del * /s /q
rmdir /s /q "C:\Users\USER\Appdata\Local\Temp"
I have no problem understanding this script until we reached the third line.
As far as I know, rmdir means to remove empty directories. But what if the directory is not empty? Then the Temp folder won't be completely wiped out, since those directories won't be deleted.
I tested the script myself though, by creating a folder in %temp% and a text document inside the folder. I typed

Code: Select all

rmdir /s /q "C:\Users\USER\Appdata\Local\Temp"
on cmd, magically enough, the folder is still gone, hence proving that the script works well to clean the whole folder. My guess is, that a text document is not equivalent to a file, hence the result.
But what is the truth behind this? Why is the folder still being deleted?

aGerman
Expert
Posts: 3706
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Script to delete Temp folders in a click

#2 Post by aGerman » 19 Aug 2018 09:08

In your former thread I told you how to get the options of a command explained. What did you figure out about rmdir, especially for option /s ?

Steffen

ahzong
Posts: 7
Joined: 04 Aug 2018 23:04

Re: Script to delete Temp folders in a click

#3 Post by ahzong » 19 Aug 2018 16:36

Hmm... It seems I need to get used to using /? myself.
Strange enough rmdir deletes everything instead of empty directories. It is different than what I googled, on the Wikipedia.
I am still quite new to this batch programming thing, I hope to get as much help as possible.
I would try to use /help and /? more often.

ShadowThief
Expert
Posts: 909
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Script to delete Temp folders in a click

#4 Post by ShadowThief » 19 Aug 2018 19:33

ahzong wrote:
19 Aug 2018 16:36
Strange enough rmdir deletes everything instead of empty directories.
That's what the /S flag does.

Post Reply