Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
setLocal ENABLEDELAYEDEXPANSION
For %%G in (*.tif) do (
    echo %%G >infile.txt
    ren %%G abc.!c!.tif
    set /a c=c+1
    echo %%G >outfile.txt
)
endlocal
share|improve this question

1 Answer 1

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
setLocal ENABLEDELAYEDEXPANSION
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
)
endlocal

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

 
discard

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.