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

Windows BatchVB Script

Avatar of undefined
Last Comment
xzay1967

8/22/2022 - Mon
NVIT

Have you tried...
rmdir /s /q "%%a"
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
NVIT

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Qlemo

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

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Bill Prew

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
Bill Prew

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
xzay1967

ASKER
@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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
xzay1967

ASKER
Worked like a champ Bil, as always, you come thru (not saying that others haven't lol)
xzay1967

ASKER
Thanks all that contributed, I hope I was fair with the points awards.
Bill Prew

Welcome, glad that was helpful.

~bp
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
NVIT

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?
xzay1967

ASKER
@NewVillageIT, the question was not specifically directed to you, but thanks for responding. Bill's final suggestion took care of that option. thanks again.