Solved Batch to append text to specific place in textfile

November 19, 2012 at 17:21:39
Specs: Windows 7
I have a text file with many of these:
case 1:
{
Image image1 = ;
pictureBox1.Image = image1;
}
x++;
break;
case 2:
{
Image image2 = ;
pictureBox1.Image = image2;
}
x++;
break;


I want to take a list of filepaths that are in a textfile and have them added after the = after image#

and also add ("texttoadd") around the filepath that is being added to the text file between the = and ;

so it could read like this
case 1:
{
Image image1 = ("Filepathtextstring that is in another textfile") ;
pictureBox1.Image = image1;
}
x++;
break;
case 2:
{
Image image2 = ("Filepathtextstring that is in another textfile) ;
pictureBox1.Image = image2;
}
x++;
break;


See More: Batch to append text to specific place in textfile

Report •


#1
November 19, 2012 at 22:53:32
I figured this part out
"
and also add ("texttoadd") around the filepath that is being added to the text file "

@echo off > filepathswbegin.txt & setLocal enableDELAYedeXpansioN
for /f "tokens=* delims= " %%a in (filepaths.txt) do (
set S=%%a
set S=!S:c=("c!
echo.!S!
) >> filepathswbegin.txt

@echo off > finalfilenames.txt & setLocal enableDELAYedeXpansioN
for /f "tokens=* delims= " %%a in (filepathswbegin.txt) do (
set S=%%a
set S=!S:.jpg=.jpg")!
echo.!S!
) >> finalfilenames.txt


Report •

#2
November 19, 2012 at 23:24:30
✔ Best Answer
Here is the re-configured version, hopefully fixing my foolish and neophytic blunder:

::===== begin batchscript
@echo off>z & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (ddplus1) do (
set /a cnt+=1
set x!cnt!=%%a
)
for /f "tokens=1*" %%a in (ddplus) do (
set out=%%a %%b
if /i "%%a" equ "image" (
for /f "tokens=1-3 delims=e " %%c in ("%%b") do (
set f=!x%%d!
call :fff
)
)
>>z echo !out!
)
goto :eof

:fff
set out=!out:;=^(%f%^);!
::==== end batchscript


Report •

#3
November 20, 2012 at 10:14:47
This batch added the filepath however it is deleting the Image word before Image#

case 717:
{
image717 = (@("C:\\Users\\Daven\\Desktop\\Nature\\DS@("C04317-1.jpg")^);
pictureBox1.Image = image717;
}
x++;
break;

it should keep like this:

case 717:
{
Image image717 = (@("C:\\Users\\Daven\Desktop\\Nature\\DS@("C04317-1.jpg")^);
pictureBox1.Image = image717;
}
x++;
break;


Report •

Related Solutions

#4
November 20, 2012 at 17:18:56
My bad! "Lame-Excuses" department reports "It was very late, and i had consumed too many beers." Try revised post #2 if you are so inclined.

Report •

#5
November 20, 2012 at 17:28:02
works, great work !

Report •


Ask Question