Tuesday, September 14, 2021

 

Batch script - create new files from template file

 In this sample you can see how to create many files from one template file in windows batch script.

Templeta file:

teplate.txt

This is generated from template.txt file. It can be any text file.

In this sample variable env.datetime is replace with !env.datetime! on any place in file.

Here to: !env.datetime!

Regards


Batch script:

createFileFromTemplate.bat
@echo off
setlocal enableDelayedExpansion
set datetimex=%date:~-4%%date:~-8,2%%date:~-12,2%%time:~0,2%%time:~3,2%%time:~6,2%
rem datetimex is formated YYYYMMDDHHMISS
set "env.datetime=%datetimex: =0%"


(
  for /f "usebackq delims=" %%A in ("template.txt") do echo %%A
) >"CreatedFile-%env.datetime%.txt"


And result is:

CreatedFile-20210914212729.txt
This is generated from template.txt file. It can be any text file.
In this sample variable env.datetime is replace with 20210914212729 on any place in file.
Here to: 20210914212729
Regards





Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?