Help needed creating batch...
Moderator: DosItHelp
-
- Posts: 3
- Joined: 02 Dec 2012 09:13
Help needed creating batch...
It has been years since I have done any batch stuff and it was pretty simplistic stuff when I did it. I used to have a friend to help me with these type things, but both of us have moved and I no longer have contact with him. I am hoping one of the pundits here could help me out?
I have a txt file named user.txt. In it each line contains a username. I would like to create a new txt file inputting the username inside a line of text and then have the new file be named with that same username variable as the file name.
Example:
user.txt contains:
Cletus
Festus
Clem
I need a new .txt created for each user in user.txt. Contained in the new file would be a common text string with the user name at the end such as:
"This is the text file for {username}."
In this example the end results would be that I end up with 3 new text files Cletus.txt, Festus.txt and Clem.txt that would contain the text string above in Cletus' case "This is the text file for Cletus." and so for each user.
My user name list actual contains about 325 users. I started to cut, paste and save each but it is very tedious and leaves room for error.
Thank you in advance for any help anyone could give me!
I have a txt file named user.txt. In it each line contains a username. I would like to create a new txt file inputting the username inside a line of text and then have the new file be named with that same username variable as the file name.
Example:
user.txt contains:
Cletus
Festus
Clem
I need a new .txt created for each user in user.txt. Contained in the new file would be a common text string with the user name at the end such as:
"This is the text file for {username}."
In this example the end results would be that I end up with 3 new text files Cletus.txt, Festus.txt and Clem.txt that would contain the text string above in Cletus' case "This is the text file for Cletus." and so for each user.
My user name list actual contains about 325 users. I started to cut, paste and save each but it is very tedious and leaves room for error.
Thank you in advance for any help anyone could give me!
Re: Help needed creating batch...
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$iFile=myNamesIndex.TXT"
for /f "useback" %%? in (
"!$iFile!"
) do >"%%~?.TXT" (
::
echo."This is the text file for {%%~?}."
)
Re: Help needed creating batch...
I dislike the %%? construct and I think Ed's "useback" will generate an error message
This should be equivalent. (also untested):
This should be equivalent. (also untested):
Code: Select all
@echo off
for /f "delims=" %%a in (' type "myNamesIndex.txt" ') do (
>>"%%a.txt" echo."This is the text file for {%%a}."
)
Re: Help needed creating batch...
useback is an abbrevation of usebackqfoxidrive wrote:I think Ed's "useback" will generate an error message

Re: Help needed creating batch...
Ed Dyreen wrote:useback is an abbrevation of usebackqfoxidrive wrote:I think Ed's "useback" will generate an error message
So it's an undocumented use... yeah?
Your code works too.
-
- Posts: 3
- Joined: 02 Dec 2012 09:13
Re: Help needed creating batch...
Thanks guys! Thank you for the quick replies! The code works fine in the example I gave. I am running into problem in my actual application due to some of the punctuation i am using I think. What I am actually trying to do is stick my variable in some html code to display a logo and link. Here is my actual application the string I am trying to get the variable into:
<a href="http://www.mosesorganic.org/ou.html?referrer=%%~?">
<img src="http://www.mosesorganic.org/images/logos/OrganicUniversityBadge.gif" width="270" height="162" alt="MOSES Organic Farming Conference" border="0" />
</a>
Is it the symbols < and > that are causing me grief? Is there any way to make this happen without all the html punctuation getting in the way?
Thanks again!
Mark
<a href="http://www.mosesorganic.org/ou.html?referrer=%%~?">
<img src="http://www.mosesorganic.org/images/logos/OrganicUniversityBadge.gif" width="270" height="162" alt="MOSES Organic Farming Conference" border="0" />
</a>
Is it the symbols < and > that are causing me grief? Is there any way to make this happen without all the html punctuation getting in the way?
Thanks again!
Mark
Re: Help needed creating batch...
Escape the symbols below with the escape character and the symbol. The escape character is ^
^<
^>
^|
^&
etc
in a special case % becomes %% (but NOT in the %%a for in do variable)
^<
^>
^|
^&
etc
in a special case % becomes %% (but NOT in the %%a for in do variable)
-
- Posts: 3
- Joined: 02 Dec 2012 09:13
Re: Help needed creating batch...
Thank you guys so very much! With your help I was able to get it. Actual you guys got it for me.
Thanks again!
Mark
Thanks again!
Mark