Solved

EASY POINTS - Batch Script Question (Kavar where are you?)

Posted on 2004-03-22
14
339 Views
Last Modified: 2010-04-17
This should be an easy one...Kavar you nailed my earlier batch script question hope you can help with this one.  

I have a webmail directory that has to be cleaned up periodically.  

C:\Mail\Data\Webmail\Usr1
C:\Mail\Data\Webmail\Usr33548
etc....

I need to have a script that will automatically delete ANY folder beginning with the phrase--> Usr

I need to wildcard the number portion because the webmail package greats folders called Usr with random numbers on the end (i.e.   Usr138,  Usr4538 etc).

I need a simple batch script that will...

1.  Delete folders starting with the name -->  Usr   in the  C:\Mail\Data\Webmail  directory

2.  The script should close kill/terminate itself when complete.  

0
Comment
Question by:TheBrothaULuv2H8
  • 8
  • 6
14 Comments
 
LVL 10

Expert Comment

by:Kavar
ID: 10651060
cd C:\Mail\Data\Webmail
for  %%a in (usr*.*) do del %%a
exit
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651170
Thanks for your quick reply.  I get error...

%%a was not expected at this time.
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10651214
what os?

remember the spacing is very important...

for[space]%%a[space]in[space](usr*.*)[space]do[space]del[space]%%a


also make sure there are actually files that match the pattern
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651258
I'm testing this on an XP Pro machine, but when it's ready to rock n roll the script will run on Windows Server 2003.

PS:  I spaced it as you stated and I got same error.  Even tried copying and pasting your exact text (obviously the one that doesn't say [space]) to no avail same error.
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10651284
hmmm, works on my xp professional....

save it as a .bat file not a .cmd
run it from the start run window
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651352
No error but the folders still exist.  Am I missing something.  The script completes ok but the folders weren't deleted.
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10651366
hmmmw thought you wanted files deleted...
change "do del %%a" to "do rd /s %%a"
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 10

Expert Comment

by:Kavar
ID: 10651369
also change usr*.* to usr*
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651448
Still no go even with your mods....

test.bat

cd C:\temp
for %%a in (usr*) do rd /s %%a
exit



I have 3 folders called
Usr1
Usr354689
Usr4287  

All three folders still exist.
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10651459
cd C:\temp
for %%a in (usr*) do rd /s /q %%a
exit


(must be asking you)
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651495
Folders still exist.  Even after your last mod here.  
0
 
LVL 10

Accepted Solution

by:
Kavar earned 150 total points
ID: 10651602
fine....(man I am stupid)

cd C:\temp1
for /F %%a in ('dir usr*. /b') do rd /s /q %%a
pause
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10651610
really sorry about that, with files my original post works fine, with directories the (usr*) doesn't work (it used to work dos 6.0 fine)

so instead we have to execute a command to get the folders to delete, thus the /F and the ('command')
0
 
LVL 2

Author Comment

by:TheBrothaULuv2H8
ID: 10651777
That's the winner.  Thank you so much!!  Extra points for your trouble
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now