rockfish12
Technical User
I have a situation where I have a bunch of text files - all within the same directory - that need to have a particular line replaced. What I want to do is programmatically open, say n07w113a4.txt, and replace the text on a line in that file with the current filename, minus the extension.
So, for example, if the sixth line was the following:
Tile Identifier #: i307113a4.tif
I would want to replace it with:
Tile Identifier #: n07w113a4.txt
Ideally, I'd like to have the code loop through every text file in the directory, and do the same exercise with each one: that is, replace part of the "Tile Identifier #" line with the file name. The tricky aspect is that the part I want to replace won't be named the same thing every time. It will, however, be on the same line as the "Tile Identifier #:" string. But, the "Tile Identifier:" string won't be in a fixed place every time within the document. It can vary, from being on the sixth line, to the fourth, etc...
Below is the typical layout of the text files:
xxxxxxx
xxxxxxx
xxxxxxx
File Creation date: March 10, 2000
Tile Identifier #: i307113a4.tif
Project Area: West and East Java
xxxxxxx
xxxxxxx
xxxxxxx
If anyone can give me any ideas or sample code on how to do this, I'd greatly appreciate it.
So, for example, if the sixth line was the following:
Tile Identifier #: i307113a4.tif
I would want to replace it with:
Tile Identifier #: n07w113a4.txt
Ideally, I'd like to have the code loop through every text file in the directory, and do the same exercise with each one: that is, replace part of the "Tile Identifier #" line with the file name. The tricky aspect is that the part I want to replace won't be named the same thing every time. It will, however, be on the same line as the "Tile Identifier #:" string. But, the "Tile Identifier:" string won't be in a fixed place every time within the document. It can vary, from being on the sixth line, to the fourth, etc...
Below is the typical layout of the text files:
xxxxxxx
xxxxxxx
xxxxxxx
File Creation date: March 10, 2000
Tile Identifier #: i307113a4.tif
Project Area: West and East Java
xxxxxxx
xxxxxxx
xxxxxxx
If anyone can give me any ideas or sample code on how to do this, I'd greatly appreciate it.