• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

for loop not working in .bat file

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
SyFy
Asked:
SyFy
2 Solutions
 
OrenRozenCommented:
hi,

in a batch file the command should be:
for %%F in (*.*) do ren "%%F" "%%~nF"
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now