Hello,
I've never written a batch file but I think my task is very straightforward and should be easy to code for batch.
I have a text file called names.txt with one name per line.
I have a .jpg file named template.jpg
These two files are in the project folder.
I want to have a batch file that I can put into that project folder and that when activated from there, will open the text file, then take the first line of the text file as a variable, then do a "save as" operation on the template.jpg file whereby the template.jpg file is saved as a new .jpg file named exactly as the first line of text from the text file.
Then to continue this function for as many names there are in the txt file, then stop.
So, on completion, the folder will contain the batch file, the text file, the original template.jpg file and one additional jpg file for each line of text in the text file.
Example:
Folder contains three files:
1. BatchSaveAS.bat batch file that I'm trying to create
2. Names.txt
3. Template.jpg
Names.txt contains following text:
John Doe
Mary F. Price
Karl Jones Jr.
Then, after running the batch file, the project folder would contain the following files:
BatchSaveAs.bat
Names.txt
Template.jpg
John Doe.jpg
Mary F. Price.jpg
Karl Jones Jr..jpg
It is important to note that the names contain spaces and periods.
Any help appreciated!
Seek batch file to "save as" many files from one per txt db
Moderator: DosItHelp
Re: Seek batch file to "save as" many files from one per txt
Try This (test it first)
Code: Select all
@Echo OFF
SET "NamesFile=Names.txt"
SET "ImageName=Template.jpg"
For /F "delims=" %%A In ('Type "%NamesFile%"') Do (
COPY "%~dp0%ImageName%" "%%A.jpg" >NUL
)
pause
Re: Seek batch file to "save as" many files from one per txt
To abc0502
I tested it and it worked perfectly on my test input file of two names.
Thank you!
John
Ref:
@Echo OFF
SET "NamesFile=Names.txt"
SET "ImageName=Template.jpg"
For /F "delims=" %%A In ('Type "%NamesFile%"') Do (
COPY "%~dp0%ImageName%" "%%A.jpg" >NUL
)
pause
I tested it and it worked perfectly on my test input file of two names.
Thank you!
John
Ref:
@Echo OFF
SET "NamesFile=Names.txt"
SET "ImageName=Template.jpg"
For /F "delims=" %%A In ('Type "%NamesFile%"') Do (
COPY "%~dp0%ImageName%" "%%A.jpg" >NUL
)
pause