- Tim
--
You could try using the FOR command:
for (%f in tmp*) do rmdir %f
--
Andreas
He screamed: THIS IS SIG!
I just tried that, but I need to be able to use other
environment variables in the script, which Command.com
doesn't seem to like... that is:
SET MYDIR=C:\a\b\c
FOR %F IN (%MYDIR%\PATTERN*) DO RMDIR %f
... doesn't work, because it doesn't seem to like %MYDIR%
in the FOR command. Any way around this you know of?
- Tim
--
http://www.computerhope.com/deltree.htm
Doesn't come with Windows 2000. It has to be something that's part
of Win2K already. You'd think they believe in simple shell scripting
sorts of syntaxs... but nooooooooo! :-)
- Tim
>On Wed, 30 Jul 2003 19:03:42 GMT, SPAMB...@BLOCKEDTOAVOIDSPAM.com
>(Spammay Blockay) wrote:
>
>>I notice that the DOS rmdir doesn't allow you to give it
>>the '*' wildcard as an argument. What does one do when one
>>needs to remove a bunch of directories if one doesn't know
>>their name, and do it in DOS?
>>
>>- Tim
--
Then issue: rmdir c:\test /s
to remove the empty folders.
Skip Knoble, Penn State
On Thu, 31 Jul 2003 18:06:54 GMT, SPAMB...@BLOCKEDTOAVOIDSPAM.com (Spammay Blockay)
wrote:
-|In article <3b7iivkfj6c2kgubi...@4ax.com>,
-|Phil D <din...@nortelnutworks.com> wrote:
-|>use deltree
-|>
-|>http://www.computerhope.com/deltree.htm
-|
-|Doesn't come with Windows 2000. It has to be something that's part
-|of Win2K already. You'd think they believe in simple shell scripting
-|sorts of syntaxs... but nooooooooo! :-)
-|
-|- Tim
-|
-|>On Wed, 30 Jul 2003 19:03:42 GMT, SPAMB...@BLOCKEDTOAVOIDSPAM.com
-|>(Spammay Blockay) wrote:
-|>
-|>>I notice that the DOS rmdir doesn't allow you to give it
-|>>the '*' wildcard as an argument. What does one do when one
-|>>needs to remove a bunch of directories if one doesn't know
-|>>their name, and do it in DOS?
-|>>
-|>>- Tim
Herman D. (Skip) Knoble, Research Associate
(a computing professional for 38 years)
Mailto:h...@psu.edu
Web: http://www.personal.psu.edu/hdk
Penn State Information Technology Services
Academic Services and Emerging Technologies
Graduate Education and Research Services
Penn State University
214C Computer Building
University Park, PA 16802-21013
Phone:+1 814 865-0818 Fax:+1 814 863-7049
Bryan
Thanks for your help, Herman, but I think I may not have
made myself clear.
In this case, I have a directory stored in the variable
name %MYDIR%. In %MYDIR% there exists a bunch of files,
and some directories, who's names I do not know.
I need to delete all the subdirectories in %MYDIR%,
and all the files in those subdirectories (ie. the
entire directory tree of each of these directories),
BUT NOT ANY OTHER FILE in %MYDIR%.
So, if I've got:
%MYDIR%\myFile1.txt
%MYDIR%\myFile2.cmd
%MYDIR%\myDir1\file1.txt
%MYDIR%\myDir2\abc
Then the directory trees %MYDIR%\myDir1 and %MYDIR%\myDir2
should be deleted, but nothing else.
Any way you can think of doing this in a batch file?
- Tim
--
Nope, RMDIR doesn't recognize wildcards -- witness:
C:\>mkdir TESTDIR
C:\>cd TESTDIR
C:\TESTDIR>mkdir A
C:\TESTDIR>mkdir B
C:\TESTDIR>dir
Volume in drive C is Local Disk
Volume Serial Number is 7CD1-879E
Directory of C:\TESTDIR
07/31/2003 12:00p <DIR> .
07/31/2003 12:00p <DIR> ..
07/31/2003 12:00p <DIR> A
07/31/2003 12:00p <DIR> B
0 File(s) 0 bytes
4 Dir(s) 25,187,280,384 bytes free
C:\TESTDIR>rmdir /s *
*, Are you sure (Y/N)? y
The filename, directory name, or volume label syntax is incorrect.
C:\TESTDIR>
Any other ideas?
- Tim
>Bryan
>
>Spammay Blockay <SPAMB...@blockedtoavoidspam.com> wrote:
>> I notice that the DOS rmdir doesn't allow you to give it
>> the '*' wildcard as an argument. What does one do when one
>> needs to remove a bunch of directories if one doesn't know
>> their name, and do it in DOS?
>
>> - Tim
>
>> --
>>
--
> I need to delete all the subdirectories in %MYDIR%,
> and all the files in those subdirectories (ie. the
> entire directory tree of each of these directories),
> BUT NOT ANY OTHER FILE in %MYDIR%.
Mhhh... is backing up the files, deleting files
and directories, then copying the files back
an option?
Is Windows Scripting Host (should be in 2K) an
Option?
I tried using MOVE to move the directories to a known
place, and even that didn't understand wildcards
the way I need it to. Is that what you're suggesting?
>Is Windows Scripting Host (should be in 2K) an
>Option?
Don't know that -- does that require writing in VBScript?
- Tim
--
Oh well, thanks anyway -- I hope someone out there knows the
answer (or if there IS an answer :-) ).
- Tim
--
> In article <bgbuia$djs$3...@wildfire.prairienet.org>,
> <p...@prairienetX.org> wrote:
>
>>Actually, I was suggesting for your example "rmdir /s TESTDIR", but I see
>>in a leter post you need to preserve TESTDIR and any files in TESTDIR. My
>>suggestion gets rid of them as well. Sotty, that's all I have.
>>
>>Bryan
>
>
> Oh well, thanks anyway -- I hope someone out there knows the
> answer (or if there IS an answer :-) ).
>
> - Tim
- - - - - - - - - - begin screen capture - - - - - - - - - -
<Win2000> c:\cmd>tree d:\junkdir
Directory PATH listing for volume MICRON
Volume serial number is 0012FC94 784B:893D
D:\JUNKDIR
????profiles
? ????user1
? ????user2
? ????user3
? ????user4
????suba
????subb
????subc
<Win2000> c:\cmd>for /f "tokens=*" %a in ('dir /ad /b d:\junkdir') do @echo remove d:\junkdir\%a /s /q
remove d:\junkdir\profiles /s /q
remove d:\junkdir\suba /s /q
remove d:\junkdir\subb /s /q
remove d:\junkdir\subc /s /q
- - - - - - - - - - end screen capture - - - - - - - - - -
If this appears to do what you want, then change '@echo remove' to 'rd'.
You may also have to add a pair of double quotes if any of your directory
names have spaces.
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
If I'm understanding you correctly, you want to keep all the files in
the folder and just delete all the directories. If you don't want to
delete all the directories, or only want to delete directories that
have certain letters in their name (e.g., delete \PORN001, \PORN002,
\P0RN003 but not \LETTERSTOGRANDMA ;) then this would be a different
story...
So, how about a simple batch file where you move the files to a
temporary location, then DELTREE the remaining contents of the folder?
E.g.,
MD C:\TEMPCOPY
XCOPY C:\MYDIR\*.* C:\TEMPCOPY
DELTREE C:\MYDIR\
XCOPY C:\TEMPCOPY\*.* C:\MYDIR
(if you don't have DELTREE, you could go use instead:
CD..
RMDIR C:\MYDIR
MD C:\MYDIR
CD C:\MYDIR
Of course, this is not an optimal solution; if you have a large number
of files the copies could take a long time, and various file
attributes (hidden, system, readonly) might cause problems... but it
doesn't seem to be the simplest.
>
>- Tim
I don't know if you've read my other postings, but the solution
requires that the deleting mechanism be able to use environment
variables and wildcards. DELTREE can do this, but I'm using Windows 2000,
which doesn't come with it.
And you can't do:
rmdir %MYVARIABLE%\*
Just try it under Windows 2000, and you'll see that rmdir doesn't
understand wildcards.
- Tim
--
cd \
cd testdir
attrib +R *.* (make the files i testdir read only.)
del *.* /s /q (this will erase all files in A and B
attrib -R *.* (remove the Read Only bit)
Now A and B are empty and testdir files are ok.
Removing just these children subdirectories IA and B) is another matter.
Assuming that all files in Testdir have a file extension, and that no directries
under c:\testdir have extensions, one could issue:
CD \
cd testdir
dir /b *. > delthem.bat
Now delthem .bat would contain only subdirectoy names for subdirecties
under c:\testdir.
One could then edit this file using edlin (or even notepad) and insert before each line
the three characters 'rd ' (wiithout quotes), and then run: delthem.bat
Crude, but works.
Skip Knoble, Penn State
On Thu, 31 Jul 2003 20:37:42 GMT, SPAMB...@BLOCKEDTOAVOIDSPAM.com (Spammay Blockay)
wrote:
-|In article <bgbuia$djs$3...@wildfire.prairienet.org>,
-| <p...@prairienetX.org> wrote:
-|>Actually, I was suggesting for your example "rmdir /s TESTDIR", but I see
-|>in a leter post you need to preserve TESTDIR and any files in TESTDIR. My
-|>suggestion gets rid of them as well. Sotty, that's all I have.
-|>
-|>Bryan
-|
-|Oh well, thanks anyway -- I hope someone out there knows the
-|answer (or if there IS an answer :-) ).
-|
-|- Tim
-|
-|>Spammay Blockay <SPAMB...@blockedtoavoidspam.com> wrote:
-|>> In article <bgboev$bnp$1...@wildfire.prairienet.org>,
-|>> <p...@prairienetX.org> wrote:
-|>>>Isn't that what "RMDIR /s <path>" does?
-|>
-|>> Nope, RMDIR doesn't recognize wildcards -- witness:
-|>
-|>> C:\>mkdir TESTDIR
-|>
-|>> C:\>cd TESTDIR
-|>
-|>> C:\TESTDIR>mkdir A
-|>
-|>> C:\TESTDIR>mkdir B
-|>
-|>> C:\TESTDIR>dir
-|>> Volume in drive C is Local Disk
-|>> Volume Serial Number is 7CD1-879E
-|>
-|>> Directory of C:\TESTDIR
-|>
-|>> 07/31/2003 12:00p <DIR> .
-|>> 07/31/2003 12:00p <DIR> ..
-|>> 07/31/2003 12:00p <DIR> A
-|>> 07/31/2003 12:00p <DIR> B
-|>> 0 File(s) 0 bytes
-|>> 4 Dir(s) 25,187,280,384 bytes free
-|>
-|>> C:\TESTDIR>rmdir /s *
-|>> *, Are you sure (Y/N)? y
-|>> The filename, directory name, or volume label syntax is incorrect.
-|>
-|>> C:\TESTDIR>
-|>
-|>> Any other ideas?
-|>
-|>> - Tim
-|>
-|>>>Bryan
-|>>>
-|>>>Spammay Blockay <SPAMB...@blockedtoavoidspam.com> wrote:
-|>>>> I notice that the DOS rmdir doesn't allow you to give it
-|>>>> the '*' wildcard as an argument. What does one do when one
-|>>>> needs to remove a bunch of directories if one doesn't know
-|>>>> their name, and do it in DOS?
-|>>>
-|>>>> - Tim
-|>>>
-|>>>> --
-|>>>>
-|>
-|>
-|>> --
-|>>
Some, not all (odd propogation on this server ;-)
>requires that the deleting mechanism be able to use environment
>variables and wildcards. DELTREE can do this, but I'm using Windows 2000,
>which doesn't come with it.
Then get it?
http://www.techadvice.cc/files/s29k2/w95b/deltree.exe
>
>And you can't do:
>
> rmdir %MYVARIABLE%\*
>
>Just try it under Windows 2000, and you'll see that rmdir doesn't
>understand wildcards.
Hmm, under WindowsXP,
rmdir %MYDIR%\
or
rmdir %MYDIR%\TEST\
both work. Don't forget the trailing slash. But perhaps 2K's rmdir
does things differently.
I was hoping to not have to add anything... it's supposed to work
without adding any new .exe's.
>>And you can't do:
>>
>> rmdir %MYVARIABLE%\*
>>
>>Just try it under Windows 2000, and you'll see that rmdir doesn't
>>understand wildcards.
>
>Hmm, under WindowsXP,
>
>rmdir %MYDIR%\
>or
>rmdir %MYDIR%\TEST\
>
>both work. Don't forget the trailing slash. But perhaps 2K's rmdir
>does things differently.
Did you try:
rmdir %MYDIR%\*
??
I'll see if adding a trailing slash makes a difference, tho'.
- Tim
--
>>>I need to delete all the subdirectories in %MYDIR%,
>>>and all the files in those subdirectories (ie. the
>>>entire directory tree of each of these directories),
>>>BUT NOT ANY OTHER FILE in %MYDIR%.
>>
>>Mhhh... is backing up the files, deleting files
>>and directories, then copying the files back
>>an option?
>
>
> I tried using MOVE to move the directories to a known
> place, and even that didn't understand wildcards
> the way I need it to. Is that what you're suggesting?
No.
copy \a\b\c\*.* c:\temp
deltree /y a\b\c
mkdir a\b\c
copy c:\temp\*.* \a\b\c
>>Is Windows Scripting Host (should be in 2K) an
>>Option?
>
> Don't know that -- does that require writing in VBScript?
I think WSH and VBS are two different things, but
it is a sort of programming language, yes.
Aaaaaaaaarrrgh! I've been spoiled by being an old unix hack!
Bad, BAD DOS! Need to be able to do: rm -fr $mydir/pattern*
Grrr. :-)
- Tim
--
>Did you try:
>
> rmdir %MYDIR%\*
Yes. Specifically, I created and filled the folder C:\TEMP\TEST with a
number of garbage files and directories. I then SET MYDIR=C:\TEMP\TEST
This I followed with the command RMDIR /S /Q %MYDIR%\ . This
successfully deleted C:\TEMP\TEST and all its contents. The /S command
is required to delete all contents, the /Q makes it work quietly,
without asking for confirmation. Without the /S command, RMDIR will
complain that the directory is not empty
As I said, this was in WinXP (Pro, SP1); it's possible RMDIR works
differently in Win2K.
Of course, after RMDIR the directory, you'd have to recreate it and
then copy the files you wanted to save back from the temp folder you
made...
>I'll see if adding a trailing slash makes a difference, tho'.
Be sure to let us know how it turns out, if only to confirm whether or
not Win2K's RMDIR works differently.
set your location to %mydir%
for /d %d in (*) do deltree "%d"
Check the switching on deltree, you might need some