Solved

for loop not working in .bat file

Posted on 2011-03-06
2
642 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

20 Experts available now in Live!

Get 1:1 Help Now