Find text file inside folder and replace string in it

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
boqsc
Posts: 12
Joined: Mon Nov 11, 2013 5:13 pm

Find text file inside folder and replace string in it

Post by boqsc » Sun Jul 13, 2014 11:55 am

So there it goes, i have no idea why i can't make it quick. I tried to do it many times before.
All i need is simple script witch looks for file in the same folder as executable, and if it finds it - change some words in it:

The file continent looks like that:

Code: Select all

...
Name = BoQsc
Name = Fenix
Name = Filly
Name = Fufy
...
I need to change it to:

Code: Select all

...
Name = none
Name = none
Name = none
Name = none
...

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Find text file inside folder and replace string in it

Post by Simon » Sun Jul 13, 2014 3:52 pm

Hi boqsc,

Code: Select all

put "name = none" & cr & "name = none" & cr & "name = none" & cr & "name = none" into url(file:myTxtFile.txt)
More fun stuff.

Simon
Edit; too early in the morning
Last edited by Simon on Sun Jul 13, 2014 3:55 pm, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Find text file inside folder and replace string in it

Post by Klaus » Sun Jul 13, 2014 3:53 pm

Hi boqsc,

do you know the name of the file?
If yes, you can do something like this (out of my head!):

Code: Select all

...
## Get the name of the folder the standalone is in:
put the effective filename of this stack into tFile
set itemdel to "/"

## Create path to your text file:
put "the_name_of_the_textfile.txt" into item -1 of tFile

## Check if file is present, if yes, put its content into a variable
## and do your processing. Then write the file back to disk.
if there is a file tFile then
  put url("file:" & tFile) into tVarWithFile
  ## Do what must be done with the content...
  ## Do you know how to carry on?
  ## Drop a line if not!
  ## ...

  ## finally write the content back to file
  put tVarWithFile into url("file:" & tFile)
end if...
BEWARE!
Not all users have write permissions in the OS application folder,
in case your standalone has been installed/copied to that folder!


Best

Klaus

Post Reply