09-05-2011, 01:04 PM
(This post was last modified: 09-05-2011, 01:06 PM by AceInfinity.)
Not sure if this will help anyone out, but I was fooling around with simple loops in batch and had this code at some point so I might as well share it.
If you run it, it will create a file named "file.txt" in the same location you ran the batch script. The file.txt will contain an empty number list template for you with however many numbers you want if you edit the "100" in my code here:
If file.txt exists in the same directory as the batch script it will not create a new file or add on to the original, and the script will exit, in case you happen to coincidentally have a file named file.txt with content that you don't want to replace or overwrite.
Note: I've had it up to 10000 for the value, don't use commas (ex: 10,000) or spaces (ex: 10 000) though. Just remember the higher the value, the more time it will take. It took me about a minute or so to create a file with 10000 numbered lines, but it depends on your system specs as well. A good safe number to have is around 1000.
Code:
@echo off
title List Creator v1.0 - Ace
set i=1
if exist file.txt goto exist
:start
if %i% GTR 100 goto end
echo %i%. > file.txt
set /a i+=1
goto start
:exist
echo The file already exists... Press any key to exit
pause>nul
:end
exit
If you run it, it will create a file named "file.txt" in the same location you ran the batch script. The file.txt will contain an empty number list template for you with however many numbers you want if you edit the "100" in my code here:
Quote:if %i% GTR 100 goto end
If file.txt exists in the same directory as the batch script it will not create a new file or add on to the original, and the script will exit, in case you happen to coincidentally have a file named file.txt with content that you don't want to replace or overwrite.
Note: I've had it up to 10000 for the value, don't use commas (ex: 10,000) or spaces (ex: 10 000) though. Just remember the higher the value, the more time it will take. It took me about a minute or so to create a file with 10000 numbered lines, but it depends on your system specs as well. A good safe number to have is around 1000.