Software >> OS >> Windows >> Command Line >> How to use FOR command to process each file matching a pattern and rename with a prefix

Example we want to loop through all files matching p????.gif and add a prefix 2010-

for /F %%a in ('dir /b  p????.gif') do rename %a 2010-%%a

 

Note:

  • When running it via a batch file use %%a
  • When running directly on a command prompt use %a