OK not strictly PS related, but I'm doing it from a javascript PS script:
So what's the simplest method to search and replace in a text file?
I could do it, but in a clumsy way! I'm unclear whether I need to read the whole file, S+R, and then re-write the whole file. I'm thinking there may be a simpler method?
Search and Replace in a text file
Re: Search and Replace in a text file
OK, well this works, but won't catch errors, and there's probably a simpler method:
But I now have a new and different problem, again to do with external local files. I'd have thought it should be extremely simple, I just want to delete a file. This doesn't work, and I really cannot work out why:
I get an error "f.Delete is not a function".
Code: Select all
#target photoshop
f = new File('C:/Users/Ian/Desktop/test.txt')
f.open('r')
var conts = f.read()
f.close
f.open('w')
newConts = conts.replace(/oldtext/g, 'newtext')
f.write(newConts)
f.close
Code: Select all
f = File('C:/Users/Ian/Desktop/test.txt')
f.Delete()
Re: Search and Replace in a text file
Thanks! I just found that solution at the same time I read your reply.