?
Solved

for loop not working in .bat file

Posted on 2011-03-06
2
Medium Priority
?
649 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

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

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

Assisted Solution

by:Qlemo
Qlemo earned 400 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 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