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

xzay1967Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITCommented:
Have you tried...
rmdir /s /q "%%a"
0
xzay1967Author Commented:
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.
0
NVITCommented:
Couple things going on...
- Remove the spaces in SET
- As I mentioned last, wrap quotes around rmdir /s /q "%%a"
rem @echo off
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

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

0
Bill PrewCommented:
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
0
Bill PrewCommented:
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
0
xzay1967Author Commented:
@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?
0
Bill PrewCommented:
This should handle what you described.

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

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xzay1967Author Commented:
Worked like a champ Bil, as always, you come thru (not saying that others haven't lol)
0
xzay1967Author Commented:
Thanks all that contributed, I hope I was fair with the points awards.
0
Bill PrewCommented:
Welcome, glad that was helpful.

~bp
0
NVITCommented:
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?
0
xzay1967Author Commented:
@NewVillageIT, the question was not specifically directed to you, but thanks for responding. Bill's final suggestion took care of that option. thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.