1.

Solve : Batch file OR...?

Answer»

I need a program OR batch file to create empty text (.txt) files based upon the first file.

For example: If the first text file is named 110612.txt i would like for the next one to be named 111312.txt (+7 days). If this is not possible, would it be possible to create and name the files in sequence... 001.txt, 002.txt, 003.txt... etc.?

I am thinking of a file that i could run... add the "prefix" for the text file... and the program would create "X" amount of files.

Is this possible?

Background... i have a PHP counter script for a web site that requires blank text files for each date. Instead of creating each file individually, i am looking for automation.It's easy to create a sequence.

This steps from 1001 to 1008 by 1 and then TAKES the last three digits to GET a zero-padded number.

Code: [Select]@ECHO off
setlocal enabledelayedexpansion
for /L %%b in (1001,1,1008) do (
set num=%%b
set num=!num:~-3!
type nul >"!num!.txt"
)
echo done
pauseBlue is a batch file, green is a screen grab of running it

@echo off
echo MyMonth = Monthname(wscript.arguments(0),True) > DateJump.vbs
echo MyDay = wscript.arguments(1) >> DateJump.vbs
echo MyYear = wscript.arguments(2) >> DateJump.vbs
echo MyJump = wscript.arguments(3) >> DateJump.vbs
echo MyNumber = wscript.arguments(4) >> DateJump.vbs
echo MyStartDate = MyMonth ^& " " ^& MyDay ^& " " ^& MyYear >> DateJump.vbs
echo MyInterval = "d" >> DateJump.vbs
echo wscript.echo FormatDate(MyStartDate) >> DateJump.vbs
echo for j = 2 to MyNumber >> DateJump.vbs
echo MyNewDate=DateAdd(MyInterval,MyJump,MyStartDate) >> DateJump.vbs
echo wscript.echo FormatDate(MyNewDate) >> DateJump.vbs
echo MyStartDate=MyNewDate >> DateJump.vbs
echo next >> DateJump.vbs
echo Public Function FormatDate (MyDate) >> DateJump.vbs
echo MyNewM = Month (MyDate) >> DateJump.vbs
echo MyNewD = Day (MyDate) >> DateJump.vbs
echo MyNewY = Year (MyDate) - 2000 >> DateJump.vbs
echo if MyNewM ^< 10 Then MyNewM = "0" ^& MyNewM >> DateJump.vbs
echo if MyNewD ^< 10 Then MyNewD = "0" ^& MyNewD >> DateJump.vbs
echo FormatDate = MyNewM ^& MyNewD ^& MyNewY >> DateJump.vbs
echo End Function >> DateJump.vbs
set /p mm="Start month: "
set /p dd="Start Day: "
set /p yy="Start Year: "
set /p jj="Jump days: "
set /p ff="No of files: "
for /f %%A in ('cscript //nologo DateJump.vbs %mm% %dd% %yy% %jj% %ff%') do (
echo Create %%A.txt
type nul > %%A.txt
)
Del DateJump.vbs
echo Done
pause



C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>dir
Volume in drive C is Win07
Volume SERIAL Number is E4DB-A92A

Directory of C:\Batch\Test\After 14-10-2012\WeeklyDate\Test

07/11/2012 21:00 <DIR> .
07/11/2012 21:00 <DIR> ..
07/11/2012 20:59 2,012 JD005.bat
1 File(s) 2,012 bytes
2 Dir(s) 31,607,975,936 bytes free

C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>jd005.bat
Start month: 11
Start Day: 7
Start Year: 2012
Jump days: 7
No of files: 6
Create 110712.txt
Create 111412.txt
Create 112112.txt
Create 112812.txt
Create 120512.txt
Create 121212.txt
Done
Press any key to CONTINUE . . .
C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>dir
Volume in drive C is Win07
Volume Serial Number is E4DB-A92A

Directory of C:\Batch\Test\After 14-10-2012\WeeklyDate\Test

07/11/2012 21:01 <DIR> .
07/11/2012 21:01 <DIR> ..
07/11/2012 21:01 0 110712.txt
07/11/2012 21:01 0 111412.txt
07/11/2012 21:01 0 112112.txt
07/11/2012 21:01 0 112812.txt
07/11/2012 21:01 0 120512.txt
07/11/2012 21:01 0 121212.txt
07/11/2012 20:59 2,012 JD005.bat
7 File(s) 2,012 bytes
2 Dir(s) 31,607,975,936 bytes free

C:\Batch\Test\After 14-10-2012\WeeklyDate\Test>








Thank you! You are AWESOME!



Discussion

No Comment Found