delete folders with wildcards

V

Vijay

I want to remove folders which starts with "s" characters , i want to use
wildcards to remove folders, , Please tll me which command i should use in
command prompt. i am using winxp sp2. folder location is c:\ (c drive) ,
 
E

Elmo

Vijay said:
I want to remove folders which start with "s" characters; I want to use
wildcards to remove folders. Please tell me which command I should use in
command prompt. I am using XP sp2. Folder location is c:\ (c drive)

Type in RMDIR /? to see the required syntax. To remove those pesky
folders, such as "System Volume Information" from the C:\ root folder,
consider this command:

RMDIR S*

Have your XP install CD and all backups nearby, of course.. there is no
Undelete command in XP.
 
V

Vijay

RMDIR S*

option is not working , i think , RMDIR command does not support wildcards,

Please help me to search the answer,
 
B

Bob I

You could use Windows Search For File and Folders, it accepts Wildcards
( find S* ) when it is done , Click File to sort them so the Folders are
at the Top, Select them all and then delete them.
 
V

Vijay

I want to delete folders with command prompt, when i run command , it should
be automatically deleted.

location of the folder my be different,
 
J

John John - MVP

The problem with that is that if you try to delete using S* wildcard you
will or may have serious problems! For example, searching for S* will
find folders like the System, System32, ServicePackFiles, and System
Volume Information folders, to name only a few. Just run the following
command and you will see what I mean:

dir c:\s* /ad /s/b

You could always run the above command and send the output to a text
file then weed out the file and then run a batch file that uses the FOR
command with your input file to delete the folders.

John
I want to delete folders with command prompt, when i run command , it should
be automatically deleted.

location of the folder my be different,
 
T

Twayne

John John - MVP said:
The problem with that is that if you try to delete using S* wildcard
you will or may have serious problems! For example, searching for S*
will find folders like the System, System32, ServicePackFiles, and
System Volume Information folders, to name only a few. Just run the
following command and you will see what I mean:

dir c:\s* /ad /s/b

You could always run the above command and send the output to a text
file then weed out the file and then run a batch file that uses the
FOR command with your input file to delete the folders.

John

Right. Without using a starting path, it could be pretty disastrous:
rmdir /? gives:

Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories
in addition to the dire
ctory tree.

/Q Quiet mode, do not ask

C:\Documents and Settings\T Wayne>
 
P

Pegasus [MVP]

Vijay said:
I want to delete folders with command prompt, when i run command , it
should
be automatically deleted.

location of the folder my be different,

As others have said, deleting folders with wildcards is dangerous business.
If you're prepared to wear the risk, here is how you can do it:
1. Copy and paste the code below into c:\Windows\DelFolder.bat.
2. Unwrap wrapped lines.
3. Make Line 3 like so: set Active=No
4. Remove the line numbers.
5. Save the file.
6. To delete all folders starting with "abc", invoke the batch file like so:
DelFolder c:\documents and settings\Vijay\abc
Do *not* write it like so:
DelFolder c:\documents and settings\Vijay\abc*
7. If you are happy with the result, set Active=Yes in Line 3. You will
be asked for a confirmation before the folder is deleted. No folder
will be deleted just yet.
8. If you are prepared to wear the risk, set Active=Rip in Line 3. You
will *not* be asked for any confirmation. No folder will be deleted
just yet.
9. If you are happy with Steps 8 and 9, remove the words "echo" in
Lines 21 and 25. The batch file will now be fully active.
Note: You run this batch file at your own risk.

[01] @echo off
[02] rem Possible values for Active: No, Yes, Rip
[03] set Active=Rip
[04] if "%*"=="" (
[05] echo Missing folder specicfication.
[06] pause
[07] goto :eof
[08] )
[09] for %%a in ("%*") do set Folder=%%~dpa
[10] for /F "delims=" %%a in ('dir /s /b /ad "%Folder%" ^| find /i "%*"') do
call :Sub %%a
[11] goto :eof
[12]
[13] :Sub
[14] if /i %Active%==Yes goto Yes
[15] if /i %Active%==Rip goto Rip
[16] echo Folder=%*
[17] goto :eof
[18]
[19] :Yes
[20] set /p confirm=Delete "%*%? (Y/N)
[21] if /i "%confirm%"=="Y" echo rd /s /q "%*"
[22] goto :eof
[23]
[24] :Rip
[25] echo rd /s /q "%*"
 

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