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 have batch file that generates one file *.txt that I use for review some details about installation process of a software, all good BUT how can I generate a new *.txt file on the same location with a different name or number?

For example: If folder C:\Users\John\Documents contains a file named ProgramLog.txt I need that the name of a new change to *.txt eg. Programlog1.txt and so on (leaving the ProgramLog.txt in the same location)

Sorry here is my batch:

msiexec /i "C:\Windows\System32\John.msi" /passive /log c:\Programlog.txt 

I added this, renames and add an extra character (number one) but overwrites the file:-(

@ECHO Off &SETLOCAL 
FOR %%a IN (*.txt) DO CALL:processFile "%%~a" 
goto:eof 

:processFile 
SETLOCAL 
:loop 
SET /a fileCounter+=1 
SET "fileName=%~n1%filecounter%%~x1" 
IF EXIST "C:\Users\%username%\Desktop\%fileName%" GOTO:loop 
ECHO MOVE "%~1" "C:\Users\%username%\Desktop\%fileName%" 
ENDLOCAL 
goto:eof 
share|improve this question
    
How are the current files being generated? changing the output in batch is just > filename –  50-3 Sep 9 '13 at 20:35
    
Why don't you supply the relevant part of your batch file that makes the file, and then someone can amend it to rename the file if needed. –  paradroid Sep 9 '13 at 20:40
add comment

1 Answer

Do you really need to keep the first file named ProgramLog.txt?  This would be simpler if you would just rename the first file to ProgramLog1.txt, the second one to ProgramLog2.txt, etc.  Because saying

msiexec … /log c:\ProgramLog.txt

is going to overwrite an existing file called ProgramLog.txt.

If you must do it this way, change the msiexec command to

msiexec … /log c:\temp.txt

and then rename temp.txt to ProgramLog.txt the first time, ProgramLog1.txt the second time, ProgramLog2.txt the third time, etc.  Alternatively, do your original command:

msiexec … /log c:\ProgramLog.txt

the first time (when ProgramLog.txt doesn’t exist), and on all subsequent runs create temp.txt and rename it.

share|improve this answer
add comment

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.