[SOLVED] How to delete folder content with command?

Jul 22, 2021
8
0
10
I want to delete all contents from this folder %temp% but not the folder itself, how do i do that?

Trying to find a simple line of code to paste into a batch file.

I tryed this:

del C:\Users\User\AppData\Local\Temp .

Not working... when removing the . it will delete the folder with it contents but i want only the contents to be gone.
 
Solution
Make a backup of the folder before you try anything.

This command should work as i just ran it on my computer. Make sure you change the second \User to the actual folder name

del "C:\Users\User\AppData\Local\Temp\." /s /f /q
rmdir /S /Q "C:\Users\User\AppData\Local\Temp\"



Drop both these in a text file and name it whatever.bat and then run it. The first string will delete everything in the temp folder and sub folders. The second string will delete any empty sub folders.
Make a backup of the folder before you try anything.

This command should work as i just ran it on my computer. Make sure you change the second \User to the actual folder name

del "C:\Users\User\AppData\Local\Temp\." /s /f /q
rmdir /S /Q "C:\Users\User\AppData\Local\Temp\"



Drop both these in a text file and name it whatever.bat and then run it. The first string will delete everything in the temp folder and sub folders. The second string will delete any empty sub folders.
 
  • Like
Reactions: cmdpowershell
Solution
Jul 22, 2021
8
0
10
Make a backup of the folder before you try anything.

This command should work as i just ran it on my computer. Make sure you change the second \User to the actual folder name

del "C:\Users\User\AppData\Local\Temp\." /s /f /q
rmdir /S /Q "C:\Users\User\AppData\Local\Temp\"



Drop both these in a text file and name it whatever.bat and then run it. The first string will delete everything in the temp folder and sub folders. The second string will delete any empty sub folders.

Thanks, does exactly what i wanted - perfect.
 

TRENDING THREADS