Creating and analyzing several text files
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Creating and analyzing several text files
Hi all,
I used to use code like the following to create data files:
put "File:PilotData.txt" into myFile
put url "File:PilotData.txt" into myData
put "test" into myData
put myData into URL myFile
but now nothing seems to work. I can't create a file regardless of how I order or work these commands. Any help for creating or retrieving data would be most appreciated!
I used to use code like the following to create data files:
put "File:PilotData.txt" into myFile
put url "File:PilotData.txt" into myData
put "test" into myData
put myData into URL myFile
but now nothing seems to work. I can't create a file regardless of how I order or work these commands. Any help for creating or retrieving data would be most appreciated!
Re: Creating and analyzing several text files
Hi Josh,
This script create if not exists, read and set the content of a file of documents folder
Best regards
Jean-Marc
This script create if not exists, read and set the content of a file of documents folder
Code: Select all
put "PilotData2.txt" into myFile
put specialfolderPath("documents") into tPathFol
put tPathFol & "/" & myFile into tPathFile
if there is a file tPathFile then
put url ("File:" & tPathFile) into myData
end if
put "test" into myData
put myData into url ("File:" & tPathFile)
Jean-Marc
https://alternatic.ch
Re: Creating and analyzing several text files
Thanks for the help! I've tried this and no file still shows up. I've tried refreshing the folder and there is no error (compile or runtime), so I'm still not sure what the problem is... I'll try making a text file and seeing if the data writes to that.
Re: Creating and analyzing several text files
This is so puzzling
None of my file code works (reading or writing).

Re: Creating and analyzing several text files
IMPORTANT: I think my program was embedded into too many subdirectories. Hopefully, this isn't premature celebration, but it seems to work if I put the program on the desktop.
Re: Creating and analyzing several text files
Final update (unless someone has two cents to add). It work near the desktop (avoiding subdirectories) and, unfortunately, it only works once (i.e., LC needs to be restarted every time for the file to be created). A bit lame, but hopefully it'll suffice.
Re: Creating and analyzing several text files
Hi Josh,
what part exactly does not work here?
Did you check "the result" or answer the variables right after the part that does not work?
And since you did not specify a complete pathname, make sure "the directory" is really set
to the folder with thaé stack whichj is executing these commands!
Or use -> specialfolderpath("resources")
which makes sure that LC is looking for the file in the same folder as the stack,
no matter in how many subdirectories the stack is "buried"!
Best
Klaus
what part exactly does not work here?
Code: Select all
...
put "File:PilotData.txt" into myFile
put url "File:PilotData.txt" into myData
put "test" into myData
put myData into URL myFile
...
Code: Select all
...
put "File:PilotData.txt" into myFile
put url "File:PilotData.txt" into myData
## Dialog should show content of the file
ANSWER myData
put "test" into myData
put myData into URL myFile
if the result <> EMPTY then
answer "Error:" && the result
end if
...
to the folder with thaé stack whichj is executing these commands!
Or use -> specialfolderpath("resources")
which makes sure that LC is looking for the file in the same folder as the stack,
no matter in how many subdirectories the stack is "buried"!
Code: Select all
...
put "File:" & specialfolderpath("resources") & "/PilotData.txt" into myFile
put url myFile into myData
...
Klaus
Re: Creating and analyzing several text files
Thanks, Klaus. This is useful. My only lingering question is why I can't write new files using the same code if I run the program a second time (i.e., I have to quit the program and then restart it). Any thoughts on that?
Re: Creating and analyzing several text files
Sorry, Josh, I have no idea!
I could offer to take a look at your stack, if you like.
If yes, send the stack and a "PilotData.txt" file to: klaus AT major-k.de

I could offer to take a look at your stack, if you like.
If yes, send the stack and a "PilotData.txt" file to: klaus AT major-k.de