Page 1 of 1

Find text file inside folder and replace string in it

Posted: Sun Jul 13, 2014 11:55 am
by boqsc
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
...

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

Posted: Sun Jul 13, 2014 3:52 pm
by Simon
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

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

Posted: Sun Jul 13, 2014 3:53 pm
by Klaus
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