Saving and loading data from .txt files

I am having a problem trying to get SaveStringToTextFile and LoadStringFromTextFile to work. I tried a simple file name but the Return Code was bad telling me GP did not create the file.

On Activate
var
rc : Boolean
FileName : String = “GPTest.txt”

rc = SaveStringToTextFile (FileName, "TestString")
Print("rc: "+BoolToString(rc))

end

So, I created the file “GPTest.txt” on my Desktop manually and then tried the code again. GP still couldn’t find it.

So, I created the file “C:\Users\Phil\Desktop\GP_test.txt” manually and then tried similar code, but GP doesn’t like the string “C:\Users\Phil\Desktop\GP_test.txt” … so, I didn’t get a chance to test this code:

On Activate
var
rc : Boolean
FileName : String = “C:\Users\Phil\Desktop\GP_test.txt”

rc = SaveStringToTextFile (FileName, "TestString")
Print("rc: "+BoolToString(rc))

end

Has anyone been successful using these functions and if so, could you plz provide a simple scriptlet?

2 Likes

Try to use a “/” instead of a backslash i can slightly remember something like that.

3 Likes

Correct. In GPScript, the file path separator is always a forward slash.

3 Likes

I ran into the same problem.

See // character inside a string (for directory names)

1 Like