I can't run by bat file

I can't run by bat file (attached)

The syntax of the command is incorrect.

FOR /R f" *.dla;
1.bat.txt
Mohammed DallagPetroleum ConsultantAsked:
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.

oBdACommented:
When used in a batch file, the loop variables for "for" must have double percent signs.
Batch commands don't end with ";"
FOR /R %%f IN (*.dll) DO REN "%%f" "*.dla"
FOR /R %%f IN (*.exe) DO REN "%%f" "*.exa"
FOR /R %%f IN (*.bat) DO REN "%%f" "*.baa"
FOR /R %%f IN (*.inf) DO REN "%%f" "*.ina"
FOR /R %%f IN (*.jar) DO REN "%%f" "*.jaa"
FOR /R %%f IN (*.zip) DO REN "%%f" "*.zia"
FOR /R %%f IN (*.msi) DO REN "%%f" "*.msa"

Open in new window

0
Paul TomasiCommented:
I notice you have included the *.bat filespec. You need to be careful your batch file does not delete itself.

One way you can accomplish this to save your batch file as .cmd rather than .bat. But bear in mind .bat programs have precedence over .cmd programs. This is only significant if you have two programs with the same name - one ending in .bat and the other in .cmd.

Another way to prevent your batch file from deleting itself is by including a conditional statement in your program. Taking oBdA's code as an example, you need to pay attention to line 3 in his code by adding the following:

@ECHO OFF

FOR /R %%f IN (*.dll) DO REN "%%f" "*.dla"
FOR /R %%f IN (*.exe) DO REN "%%f" "*.exa"

FOR /R %%f IN (*.bat) DO (
   IF NOT "%%f"=="%~dpnx0" (
      REN "%%f" "%%~dpnf.baa"
   )
)

FOR /R %%f IN (*.inf) DO REN "%%f" "*.ina"
FOR /R %%f IN (*.jar) DO REN "%%f" "*.jaa"
FOR /R %%f IN (*.zip) DO REN "%%f" "*.zia"
FOR /R %%f IN (*.msi) DO REN "%%f" "*.msa"

Open in new window

This can be condensed into a single line of code as in the following:

FOR /R %%f IN (*.bat) DO IF NOT "%%f"=="%~dpnx0" REN "%%f" "%%~dpnf.baa"

Open in new window

And this then gives us:

@ECHO OFF

FOR /R %%f IN (*.dll) DO REN "%%f" "*.dla"
FOR /R %%f IN (*.exe) DO REN "%%f" "*.exa"
FOR /R %%f IN (*.bat) DO IF NOT "%%f"=="%~dpnx0" REN "%%f" "%%~dpnf.baa"
FOR /R %%f IN (*.inf) DO REN "%%f" "*.ina"
FOR /R %%f IN (*.jar) DO REN "%%f" "*.jaa"
FOR /R %%f IN (*.zip) DO REN "%%f" "*.zia"
FOR /R %%f IN (*.msi) DO REN "%%f" "*.msa"

Open in new window

It's your choice as it's a matter of preference.

Another way of rewriting this code is to put all the filespecs into a single FOR /R loop as follows:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /R %%f IN (*.dll *.exe *.bat *.inf *.jar *.zip *.msi) DO (
  IF NOT "%%~dpnxf"=="%~dpnx0" (
    SET Extension=%%~xf
    REN "%%~dpnxf" "%%~dpnf.!Extension:~0,-1!a"
  )
)

Open in new window

But it's not efficient because we don't really want to execute the IF conditional statement for all filespecs.
1

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
Paul TomasiCommented:
Thank you
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.

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.