Link to home
Start Free TrialLog in
Avatar of Bob Brown
Bob Brown

asked on

Deleting from user profile subfolders using batch or line command

I am trying to delete a text file from all of the user profiles within the c:\Users and F:\Users on a Windows 2008 r2 server, using Del /q /f /s c:\users\%user profile%\folder1\folder2\*.txt. which does not work, and the error says path not found.   I need to delete the text file from all the users folders on the server.

how can I make it work.
Avatar of Bill Prew
Bill Prew

Give this a try, should do what you want.

Notice that it is in TEST mode currently, run it in a new command window, and it will display the DEL commands it would execute but not actually execute them (no files will be deleted yet).  This allows you to run it and inspect the console output to verify it will delete the desired files.  Then if all looks well removes the "ECHO" before the DEL command and rerun.

@echo off
setlocal

for %%A in (C:\Users,F:\Users) do (
    for /d %%B in ("%%~A\*") do (
        ECHO del /q /f /s "%%~B\folder1\folder2\filename.txt"
    )
)

Open in new window


»bp
ASKER CERTIFIED SOLUTION
Avatar of Michael Machie
Michael Machie
Flag of United States of America 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