Solved Del Defect


TM21

Banned
Local time
2:30 PM
Posts
252
I use the "del" command in my Cleanup.bat file but I've discovered a defect in the command.

If I use it to delete a "temp" folder, it will delete all the files in that folder, but, if there are sub-folders it will not delete those.

I know that a folder does not take up a LOT of space on the HD, but it does occupy SPACE.

Using the "del" command does delete files but not folders.
So, my question: Is there maybe a newer command that I'm unaware of, that will delete not only files but their folders as well?

Merry Christmas everyone!
TM :cool:
 

My Computer

just tested and del \testlocation\* deleted everything inside "testlocation"
 

My Computer

System One

  • OS
    Windows 11 Pro
Hello mate, :alien:

The "rd" or "rmdir" command would also be good for this.



ex:
rd /s /q "full path of folder"
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    CyberPower CP1500PFCLCD
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Surface Laptop 7 Copilot+ PC
    CPU
    Snapdragon X Elite (12 core) 3.42 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Monitor(s) Displays
    15" HDR
    Screen Resolution
    2496 x 1664
    Hard Drives
    1 TB SSD
    Internet Speed
    Wi-Fi 7 and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender
can also use powershell:

Code:
remove-item testlocation\*
 

My Computer

System One

  • OS
    Windows 11 Pro
OK, the actual command would have to be:
PowerShell remove-item C:\Users\%UserName%\AppData\Local\Temp\*

However, it requires a "Y" to get it to complete without asking me for keyboard input.
So, (a dumb question) where do I put the "Y" ?
 

My Computer

If I use the rd command, it would remove the temp directory, but would fail to remove the files. Weird Science!
 

My Computer

Odd. Did you use the command below?

Any error messages? Ex: "The process cannot access the file because it is being used by another process."

rd /s /q "%LocalAppData%\Temp"
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    CyberPower CP1500PFCLCD
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Surface Laptop 7 Copilot+ PC
    CPU
    Snapdragon X Elite (12 core) 3.42 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Monitor(s) Displays
    15" HDR
    Screen Resolution
    2496 x 1664
    Hard Drives
    1 TB SSD
    Internet Speed
    Wi-Fi 7 and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender
In PowerShell, it would be
Powershell:
rm $env:Temp\* -Recurse -Force
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
The original Power Shell command I tried, worked, but stopped to ask me to index a Y or N before it would complete.
But my question is: Where do I put the Y in the command line?
 

My Computer

You don't put a Y. You use the command I posted.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
OK, I guess I'm just not understanding that command.
It doesn't specify the exact path to the files that I want to delete.
 

My Computer

Ah...

Alias for Remove-Item
Powershell:
rm

Use the environment variable for the User's temp directory
Powershell:
$env:Temp\*

Process child items as well
Powershell:
-Recurse

Just do it, don't ask me questions
Powershell:
-Force
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
Just do it? I'm terribly sorry, but I just don't work that way.

See the path in the command line that I spoke of in my original post.
That's the only location that I want to work with, using the command.
That command, as I wrote it, works fine to delete all the files in that specific "Temp" folder, but it just doesn't remove the sub-folders that the files live in.
So I was just looking for a command, if there is one, that would clean out the folders as well as the files.
If that's not possible, that's OK. The folders don't take up all that much room.
 

My Computer

just create an elevated batch that runs the command i gave you

EDIT:
you can reference this thread for a template:
 

My Computer

System One

  • OS
    Windows 11 Pro
To answer any PS prompt as always Yes.
Code:
Remove-Item .\Folder -Recurse -Confirm:$false

-Force implies forced override of default write protections, which implicitly grants you /y (if you have rights).
 

My Computer

System One

  • OS
    Windows 7
OK, I think I have it now:
I used this command:
PowerShell rm C:\Users\%UserName%\AppData\Local\Temp\* -Recurse -Force

....and I got the desired result....all non-open files and folders are GONE, only four open files remain.

However, the command left me with a bunch of RED error lines, when it hit those open temp files.
Power Shell kind of goes nutso when it hits something it can't do! It's error messages are very VERBOSE!

Thanks for the help!

Merry Christmas
TM :cool:
 

My Computer

You can run this below instead with the -ErrorAction SilentlyContinue parameter added at the end to have it ignore the errors.

PowerShell rm C:\Users\%UserName%\AppData\Local\Temp\* -Recurse -Force -ErrorAction SilentlyContinue
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    CyberPower CP1500PFCLCD
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Surface Laptop 7 Copilot+ PC
    CPU
    Snapdragon X Elite (12 core) 3.42 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Monitor(s) Displays
    15" HDR
    Screen Resolution
    2496 x 1664
    Hard Drives
    1 TB SSD
    Internet Speed
    Wi-Fi 7 and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender
Thank you Brink! That got rid of half a screen of RED error messages.

OK, I think I have it now! I'll mark this question as 'Solved'.
 

My Computer

Just do it? I'm terribly sorry, but I just don't work that way.

See the path in the command line that I spoke of in my original post.
That's the only location that I want to work with, using the command.
That command, as I wrote it, works fine to delete all the files in that specific "Temp" folder, but it just doesn't remove the sub-folders that the files live in.
So I was just looking for a command, if there is one, that would clean out the folders as well as the files.
If that's not possible, that's OK. The folders don't take up all that much room.
I wasn't telling you to just do it. I was explaining what -Force does, in plain English.

And the path I gave, $env:Temp\*, is the same as yours, C:\Users\%UserName%\AppData\Local\Temp\*, without the excess length.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
I've been careful, in my batch file, to be very specific about what I delete, so no system files, etc., get accidentally deleted.
I never loose any of the important info stored for me, by my browsers, because I only delete the Temporary Internet Files.
I guess it's probably NOT for everyone, but it's worked for me, for years, since my first attempt, years ago.
And, it's worked for the hundreds of my customers who I've shared it with.

Merry Christmas, Everyone,
TM :cool:
 

My Computer

Back
Top Bottom