Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

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

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
TheBrothaULuv2H8
Asked:
TheBrothaULuv2H8
  • 8
  • 6
1 Solution
 
KavarCommented:
cd C:\Mail\Data\Webmail
for  %%a in (usr*.*) do del %%a
exit
0
 
TheBrothaULuv2H8Author Commented:
Thanks for your quick reply.  I get error...

%%a was not expected at this time.
0
 
KavarCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
TheBrothaULuv2H8Author Commented:
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
 
KavarCommented:
hmmm, works on my xp professional....

save it as a .bat file not a .cmd
run it from the start run window
0
 
TheBrothaULuv2H8Author Commented:
No error but the folders still exist.  Am I missing something.  The script completes ok but the folders weren't deleted.
0
 
KavarCommented:
hmmmw thought you wanted files deleted...
change "do del %%a" to "do rd /s %%a"
0
 
KavarCommented:
also change usr*.* to usr*
0
 
TheBrothaULuv2H8Author Commented:
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
 
KavarCommented:
cd C:\temp
for %%a in (usr*) do rd /s /q %%a
exit


(must be asking you)
0
 
TheBrothaULuv2H8Author Commented:
Folders still exist.  Even after your last mod here.  
0
 
KavarCommented:
fine....(man I am stupid)

cd C:\temp1
for /F %%a in ('dir usr*. /b') do rd /s /q %%a
pause
0
 
KavarCommented:
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
 
TheBrothaULuv2H8Author Commented:
That's the winner.  Thank you so much!!  Extra points for your trouble
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now