replace string in filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alex1982
Posts: 1
Joined: 10 Oct 2008 07:11

replace string in filename

#1 Post by alex1982 » 10 Oct 2008 07:28

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 ?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 19 Oct 2008 12:36

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?

Post Reply