Software >> OS >> Windows >> Command Line >> For >> 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

## For example to rename the folders Topic.nn to Topic.0nn


 

Note:

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