Link to home
Start Free TrialLog in
Avatar of dmason72
dmason72

asked on

Batch to del all files within a users folder in Win 8.1

Having trouble getting command to run and get "cannot find path specified".

Trying to delete specific files under user's folder (..."appdata\local\client folder") but not having any luck.

Files are under any user within specified AppData\local\client app folder.

I'd like to call the batch on login to clear out the folder whenever a user logs into windows if possible.

Thank you in advance!
Avatar of Kanti Prasad
Kanti Prasad

Hi

You can try one of them


del /p /s c:\AppData\local\client\yourfilename.ext


For /F "tokens=*" %%I in ('Dir c:\AppData\local\client\yourfilename.ext /s /b') do set FOUND="%%~fI"
del %FOUND%
Avatar of Steve Knight
Is this running as the user on logon through logon script or startup group etc?

DEL /Q /S "%USERPROFILE%\Local Settings\MyApp\*.*"
or DEL /Q /S "%USERPROFILE%\Local Settings\MyApp\*.whatever"

or to remove a dir:

rd /s /q "%USERPROFILE%\Local Settings\MyApp"

Steve
Avatar of dmason72

ASKER

This will not work and thus the issue I'm having since the AppData folder varies with user profile name off of root therefore above path is not correct

(example "c:\users\%username%\AppData\Local\Client folder name\ where files being removed would be *.*).

How do I account for varying client app folder names (based on versions) and under different user profiles?
Steve,

This is running as user on logon and are all files in that folder so:

DEL /Q /S "%USERPROFILE%\Local Settings\MyApp\*.*"
 or DEL /Q /S "%USERPROFILE%\Local Settings\MyApp\*.whatever"

Dan
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Simple enough...used del /Q /S "%userprofile%\AppData\Local\client app folder version\*.*"

it deleted all files successfully once I confirmed path by entering it into cmd via start field.

Named file cleanmedia.bat so now I'm onto the next step to reference it in a new vb script and enter in AD scripts field per user.

Thanks everyone who took the time to put in their two cents and special thanks to Steve on this one for all the additional input.

Dan