Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to rename files with a batch command and capture the original and renamed files in a list in order to provide a cross reference (doing a DIR /OS >file both before and after the batch file is not rigourous enough).

The file below carries out the renaming fine, but my understanding is not good enough to get the output bit working (if it even is possible). Also, the output in the example below is different depending on whether output is to file or screen.

I want to be able to understand more of this:

@echo off
set /a c=%1
For %%G in (*.tif) do (
    echo %%G >infile.txt
    ren %%G abc.!c!.tif
    set /a c=c+1
    echo %%G >outfile.txt
share|improve this question

After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.

set /a c=%1
set param=%2
FOR  %%i in (*.tif) do (
        echo %%i >>in.txt
        ren %%i %param%!c!.tif
        echo %param%!c!.tif >>out.txt
        set /a c=c+1

All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.