Notifications
Clear all

[Closed] How create a external File?

lo,
the file is being created at:<File:C:\Documents and Settings\Administrator\Desktop\grakScripts est.objekt>
the script is creating the test.objekt file in the same directory as the script thats running. I think thats the default location if you don’t supply a dir, I’m probably wrong on that one though.

Got it working


    f=createFile "test.objekt"
    format "line1:%" "data1
" to:f
    format "line2:%" "data2" to:f
    close f
    o=openFile "test.objekt" mode:"r+"
    skipToString o "line2:"
    myReadData = readChars o 5
    print myReadData
    

Needed to read in the data!

Here’s a better way of doing that (can read in the whole line instead of certain number of characters)


  f=createFile "test2.objekt"
  format "Name:%" "myName
" to:f
  format "Type:%" "myType
" to:f
  format "Size:%" "155.548
" to:f
  format "Created:%" "01.12.11
" to:f
  close f
  o=openFile "test2.objekt" mode:"r+"
  skipToString o "Size:"
  myReadData = readLine o
  print myReadData
  close o
  

I do it slightly differently in that I create a stringstream and then at the end of the string-stream do a:

format stringstreamVar to:fileVar

what I like about doing it that way is you can put all of your file creation at the end of the string creation and a crash or error won’t leave an orphaned file.

Also instead of using “createfile” I’ll often do:

openFile filePath mode:"w"

which will create a file if it doesn’t exist, or overwrite an existing file.

thatoneguy – awesome tips man! i’ll be adopting your methods

Page 2 / 2