Page 1 of 1

replace string in filename

Posted: 10 Oct 2008 07:28
by alex1982
hi
i want to execute lpr command replacing a substring in the filename
for example

LPR -S 192.168.3.20 -P AUTO d:\sample.txt

I want to replace the word sample with test because i really want to print file d:\test.txt

Is there any way i can do this with one command ?

Posted: 19 Oct 2008 12:36
by DosItHelp
Here is a batch file you can try using as a external command.
http://www.dostips.com/?t=Batch_FindAndReplace

Replace the string and dump the new filename on the screen:

Code: Select all

BatchSubstitute.bat "d:\sample.txt" "d:\test.txt" File.bat

If you are happy with the resulting batch file, pipe it into a newfile and run it:

Code: Select all

BatchSubstitute.bat "d:\sample.txt" "d:\test.txt" File.bat>NewFile.bat
NewFile.bat

DosItHelp?