Link to home
Start Free TrialLog in
Avatar of xzay1967
xzay1967

asked on

Script help

Hi I am trying to delete some folders, lots of them, but having some trouble with my script. I welcome some help please, thanks in advance. Here is what I have so far, I am trying to delete all folders with the name Oracle Weblogic that located in c:\programdata\microsoft\windows\start menu\programs folder. I am open to a vb script option as well
SETLOCAL ENABLEDELAYEDEXPANSION
set pgm_folder = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
CD "%pgm_folder%"
for /d %%a in ("Oracle WebLogic*") do rmdir /s /q %%a

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

Have you tried...
rmdir /s /q "%%a"
Avatar of xzay1967
xzay1967

ASKER

Yes, rm does not accept wildcards. There are multiple folders that have the name weblogic in it. I could use rmdir if I wanted to name each folder.
SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are not using rm, or wildcards in rmdir, so your reply does not make sense.
Your original code does not work because (a) you add spaces to the var name (!), and (b) have double double quotes.
SETLOCAL ENABLEDELAYEDEXPANSION
pushd C:\ProgramData\Microsoft\Windows\Start Menu\Programs\
for /d %%a in ("Oracle WebLogic*") do rmdir /s /q %%a
popd

Open in new window

Are all the folders exactly in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\", or are they in subfolders levels below that?

Are the folders you want to delete named exactly "Oracle WebLogic", or do you want to delete all folders that start with that name?

~bp
Here's a slightly different aproach you can try.

If you are just looking for the folders that start with "Oracle Weblogic" in the single folder you specified, then this will do that.

@echo off
set pgm_folder=C:\ProgramData\Microsoft\Windows\Start Menu\Programs
set find_folder=Oracle Weblogic*.*
for /f "tokens=*" %%a in ('dir /ad /b "%pgm_folder%\%find_folder%"') do (
  rmdir /s /q "%pgm_folder%\%%~a"
)

Open in new window


If you are looking for all folders named "Oracle Weblogic" in any folder below the folder you specified, then this will do that.

@echo off
set pgm_folder=C:\ProgramData\Microsoft\Windows\Start Menu\Programs
set find_folder=Oracle Weblogic
for /f "tokens=*" %%a in ('dir /ad /b /s "%pgm_folder%\%find_folder%"') do (
  rmdir /s /q "%%~a"
)

Open in new window


~bp
@Bill, all the folders are exactly in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\". There are a variety of folders that have the word oracle in it, oracle weblogic, orcale weblogic (beahome) oracle common home, oracle application developer to name a few (there are multiple iterations of all the folders). There all located exactly in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\.  My initial approach was to just look for all folders that have oracle in by using oralce*, but there is one folder called Oracle that must not be deleted.
@NewVillageIT (NVIT), my apologies, I did not notice the quotes in your suggestion. I did however apply your code and it worked fine as well.

Is it possible to the leave folder called Orcale, but still delete the other folders named Oracle  xxx xxxx without defining each variation?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked like a champ Bil, as always, you come thru (not saying that others haven't lol)
Thanks all that contributed, I hope I was fair with the points awards.
Welcome, glad that was helpful.

~bp
Thanks, xzay..

> Is it possible to the leave folder called Orcale, but still delete the other folders named Oracle  xxx xxxx without defining each variation?
Not sure if the question is directed to me. My solution works. I just confirmed. Do you need help with this?
@NewVillageIT, the question was not specifically directed to you, but thanks for responding. Bill's final suggestion took care of that option. thanks again.