I am newbie to DOS .... I am aware of all basic commands of DOS and not sure how to build a batch ..
In the below path .. I am looking to delete all files in the below path in c:\users\ which has the appdata\temp directory structure.
* includes all directories.
C:\users\*\appdata\temp\*
Could anyone please help me in deleting those such files and directoreis .
DOS batch for deleting files with directory with regex
Moderator: DosItHelp
-
- Posts: 1
- Joined: 23 Sep 2015 10:05
Re: DOS batch for deleting files with directory with regex
Code: Select all
@echo off
pushd C:\users
for /F "delims=" %%G in ('dir /b /ad /s ^|findstr /I /E "appdata\temp"') do rmdir /s /q "%%~G"
popd
Re: DOS batch for deleting files with directory with regex
This is based on Squashman's code with a couple of extra bits.
It checks for the location of the USERS folder, and leaves the temp folder in place.
It also removes the expected error messages, that can occur, from the screen.
It checks for the location of the USERS folder, and leaves the temp folder in place.
It also removes the expected error messages, that can occur, from the screen.
Code: Select all
@echo off
:: deletes files and folders in all user accounts, in "appdata\local\temp" - untested
for %%A in ("%USERPROFILE%") do (
for /F "delims=" %%G in ('dir "%%~dpA" /b /ad /s ^|findstr /I /E "appdata\local\temp"') do (
echo removing files and folders in "%%~G"
pushd "%%~G" && (rd /s /q "%%~G" >nul 2>&1 & popd)
)
)
pause