"del /s foo*" doesn't work

R

Roof Fiddler

What's the command-line command to recursively delete all files and
directories with names beginning with "foo"?
"del /s foo*" doesn't work.

Doing it using the GUI, with Start/Search and searching for "name:foo" and
then selecting all and choosing "delete", doesn't work, because I have
hundreds of such directories, and for each one Vista will grind away on my
disk for a couple minutes and then give me a bogus "This folder is shared
with other people--If you delete this folder, it will no longer be
shared.--Continue or Cancel" message and make me press "Continue" before it
will grind away for another couple minutes and give me another bogus message
for the next folder, and there's no "Yes to All" button, so I have to sit
for hours babysitting the machine and pressing "Continue" over and over in
order to delete all the directories.
So until MS fixes that bug, I need to do it from the command line.

So what's the command to do it?
 
R

Roof Fiddler

DMB said:
Did you try doing this while running the command prompt as Administrator?
That shouldn't be necessary, since the logged-in user owns the files and
folders in question.
 
K

Kerry Brown

You're right it shouldn't be necessary but did you try it? Vista is still a
beta and may have bugs. Running an elevated cmd prompt is a valid test to
see if there are some permissions issues or maybe a bug.
 
J

Jimmy Brush

I tried this on my system and it worked fine. Can you give more information
as to what files you are trying to delete and what response you are getting
from the command prompt?
 
R

Roof Fiddler

Jimmy Brush said:
I tried this on my system and it worked fine. Can you give more information
as to what files you are trying to delete and what response you are getting
from the command prompt?

I open cmd.exe as administrator, and:

C:\Windows\system32>mkdir foo
C:\Windows\system32>mkdir foo\bar
C:\Windows\system32>mkdir foo\bar\baz

C:\Windows\system32>dir /s bar
[snip]
Directory of C:\Windows\system32\foo
11/01/2006 10:05 AM <DIR> bar
0 File(s) 0 bytes
[snip]
C:\Windows\system32>dir /s baz
[snip]
Directory of C:\Windows\system32\foo\bar
11/01/2006 10:06 AM <DIR> baz
0 File(s) 0 bytes
[snip]

C:\Windows\system32>del /s bar

C:\Windows\system32>dir /s bar
[snip]
Directory of C:\Windows\system32\foo
11/01/2006 10:05 AM <DIR> bar
0 File(s) 0 bytes
[snip]
C:\Windows\system32>
C:\Windows\system32>dir /s baz
[snip]
Directory of C:\Windows\system32\foo\bar
11/01/2006 10:06 AM <DIR> baz
0 File(s) 0 bytes
[snip]

So, even though "del /s bar" returns no error message, neither bar nor its
contents (baz) are actually deleted.
Yes, I know how to actually get rid of bar and baz in this case. The problem
is that I might have many directories named "bar" scattered throughout
various other subdirectories of my current directory, and I need a single
command which, when run from my current directory, will delete all of them
and their contents.
 
G

Guest

Roof Fiddler said:
So, even though "del /s bar" returns no error message, neither bar nor its
contents (baz) are actually deleted.

This is driving me crazy too. I have the exact same problem in both Vista
AND XP and really need an answer from someone smarter than me...
What's most frustrating is that the del command help states "Wildcards may
be used to delete multiple files. If a directory is specified, all files
within the directory will be deleted." But it simply doesn't happen.

The best I have come up with so far is to copy DELTREE command into the
system and use the following batch file to creates a list of the directories
you want to delete:

cd %1
dir /s BAR /a /b /-p /o:GEN >"C:\Documents and Settings\%USERNAME%\Local
Settings\Temp\dirlist.txt"
copy "C:\Documents and Settings\%USERNAME%\Local Settings\Temp\dirlist.txt" %1
del "C:\Documents and Settings\%USERNAME%\Local Settings\Temp\dirlist.txt"

and then turn that "dirlist.txt" into a .bat file with the 'deltree' command
in front of each line in quotes. Run it and voila!
(Very oldschool, but at least it works.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top