Page 1 of 1

Script to delete Temp folders in a click

Posted: 19 Aug 2018 08:37
by ahzong
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?

Re: Script to delete Temp folders in a click

Posted: 19 Aug 2018 09:08
by aGerman
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

Re: Script to delete Temp folders in a click

Posted: 19 Aug 2018 16:36
by ahzong
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.

Re: Script to delete Temp folders in a click

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