Solved

for loop not working in .bat file

Posted on 2011-03-06
2
639 Views
Last Modified: 2012-08-14
I am calling this for loop in my .bat file  but it doesn't work.  When i type it at the command prompt, it works. I am new to scripting.

for %F in (*.*) do ren "%F" "%~nF"
0
Comment
Question by:SyFy
2 Comments
 
LVL 3

Accepted Solution

by:
OrenRozen earned 400 total points
ID: 35047045
hi,

in a batch file the command should be:
for %%F in (*.*) do ren "%%F" "%%~nF"
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 100 total points
ID: 35047222
Correct. The reason for that is the special and different meaning of % as both FOR and environment variable deliimiter. The cumbersome syntax that the FOR var is only started by %, but not ended, introduces several issues. As a rule of thumb: always use two percents for FOR vars in a batch.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now