Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Thanks in advance the posts on here have
been very helpful and I am almost done. I have
a directory of text files that were created from
a template. Each one has a line that says
1111.pdf. I am need to have a batch file that
will take the file name of each text file and
replace the 1111 with the filename of the that
particular text file. Again any help is
appreciated!

"replace the 1111 with the filename of the that particular text file"
What is the text file? Does it have the file names in it? Give us an example of what is in the txt file?

Let's say the file is name joe.txt. I want to replace the 1111
in the joe.txt file with joe. The text file is an html file with
several lines in it. The lines around where I want to replace
are as follows:<object
id="PDFObj"
data="../pdf/1111.pdf"
type="application/pdf"
width="100%" height="100%"/>

@echo off & setLocal enableDELAYedexpansion
for /f "tokens=* delims= " %%f in ('dir/b *.txt') do (
type nul > newfile
for /f "tokens=* delims= " %%a in (%%f) do (
set S=%%a
set S=!S:1111=%%~Nf!
>> newfile echo !S!
)
copy newfile %%f > nul
)
del newfile
=====================================
Helping others achieve escape felicityM2

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |