Discussion:
Recursive File Delete
(too old to reply)
Buck Turgidson
2009-11-06 19:43:56 UTC
Permalink
I need to delete files from a subdirectory under a bunch of profiles. In
other words, I have users john, jim, and jill as

c:\documents and settings\john
c:\documents and settings\jim
c:\documents and settings\jill

And each of their profiles has a subdirectory called apps. In each apps
file for them, I need to delete all .txt files, but only from the apps
subdirectory of their profile.

c:\documents and settings\john\apps
c:\documents and settings\jim\apps
c:\documents and settings\jill\apps

Can anyone help me?
Pegasus [MVP]
2009-11-06 19:54:31 UTC
Permalink
Post by Buck Turgidson
I need to delete files from a subdirectory under a bunch of profiles. In
other words, I have users john, jim, and jill as
c:\documents and settings\john
c:\documents and settings\jim
c:\documents and settings\jill
And each of their profiles has a subdirectory called apps. In each apps
file for them, I need to delete all .txt files, but only from the apps
subdirectory of their profile.
c:\documents and settings\john\apps
c:\documents and settings\jim\apps
c:\documents and settings\jill\apps
Can anyone help me?
By far the simplest method is based on a batch file like so:
@echo off
for %%a in (John Jim Jill) do del /s "c:\Documents and
Settings\%%a\apps\*.txt"

Since the command consists of a single line, you could even type it at the
Command Prompt like so:
for %a in (John Jim Jill) do del /s "c:\Documents and
Settings\%a\apps\*.txt"
Note the double versus single % characters.

Or maybe this:
del /s "c:\Documents and Settings\John\apps\*.txt"
del /s "c:\Documents and Settings\Jill\apps\*.txt"
del /s "c:\Documents and Settings\Jim\apps\*.txt"
Buck Turgidson
2009-11-06 20:04:35 UTC
Permalink
Thanks for the help. The problem is that the actual number of profiles is
both variable and quite large. I guess that is the toughest nut to crack.
Post by Pegasus [MVP]
Post by Buck Turgidson
I need to delete files from a subdirectory under a bunch of profiles. In
other words, I have users john, jim, and jill as
c:\documents and settings\john
c:\documents and settings\jim
c:\documents and settings\jill
And each of their profiles has a subdirectory called apps. In each apps
file for them, I need to delete all .txt files, but only from the apps
subdirectory of their profile.
c:\documents and settings\john\apps
c:\documents and settings\jim\apps
c:\documents and settings\jill\apps
Can anyone help me?
@echo off
for %%a in (John Jim Jill) do del /s "c:\Documents and
Settings\%%a\apps\*.txt"
Since the command consists of a single line, you could even type it at the
for %a in (John Jim Jill) do del /s "c:\Documents and
Settings\%a\apps\*.txt"
Note the double versus single % characters.
del /s "c:\Documents and Settings\John\apps\*.txt"
del /s "c:\Documents and Settings\Jill\apps\*.txt"
del /s "c:\Documents and Settings\Jim\apps\*.txt"
Buck Turgidson
2009-11-06 20:15:38 UTC
Permalink
Thanks.

for /d %a in (*)

seems to do it, if not a bit crudely.
Post by Pegasus [MVP]
Post by Buck Turgidson
I need to delete files from a subdirectory under a bunch of profiles. In
other words, I have users john, jim, and jill as
c:\documents and settings\john
c:\documents and settings\jim
c:\documents and settings\jill
And each of their profiles has a subdirectory called apps. In each apps
file for them, I need to delete all .txt files, but only from the apps
subdirectory of their profile.
c:\documents and settings\john\apps
c:\documents and settings\jim\apps
c:\documents and settings\jill\apps
Can anyone help me?
@echo off
for %%a in (John Jim Jill) do del /s "c:\Documents and
Settings\%%a\apps\*.txt"
Since the command consists of a single line, you could even type it at the
for %a in (John Jim Jill) do del /s "c:\Documents and
Settings\%a\apps\*.txt"
Note the double versus single % characters.
del /s "c:\Documents and Settings\John\apps\*.txt"
del /s "c:\Documents and Settings\Jill\apps\*.txt"
del /s "c:\Documents and Settings\Jim\apps\*.txt"
Pegasus [MVP]
2009-11-06 20:42:08 UTC
Permalink
Post by Buck Turgidson
Thanks.
for /d %a in (*)
seems to do it, if not a bit crudely.
Indeed it does - congratulations for working it out for yourself! For your
next post I recommend that you state *all* requirements right in the
beginning.

Loading...