How To ...‎ > ‎

Text Files

Working with Text Files

1. Reading In Files

    Reading a Text File - Knowing the filename:
        put URL ("File:/Users/example/scores.txt") into field "FileIn"    - puts it into a field called "FileIn"
            or
        put URL ("File:/Users/example/scores.txt") into x     - puts it into a variable called x


    Reading a Text File - Selecting the file
        
        Any type of file:
    local tFile
    answer file "Select the File to load:"
    put it into tFile
    if tFile is empty then 
        exit mouseUp
    else
        put URL ("file:" & tFile) into field "fileIn"
    end if
    

       Only CSV file:
    local tFile
    answer file "Select the File to load:"  with type "Comma Separated Values|CSV"
    put it into tFile
    if tFile is empty then 
        exit mouseUp
    else
        put URL ("file:" & tFile) into field "fileIn"
    end if

       Only Text files:
    use - answer file "Select the File to load:"  with type "text files|TXT"

        see the Dictionary for other file types

2. Writing Out Files

    Writing a Text File - Knowing the filename:
        put x into URL ("File:/Users/example/scores.txt")    
            or
        put field "FileIn" into URL ("File:/Users/example/scores.txt")    
 

    Writing a Text File - Selecting the file name    
         ask file "Save to?"  with type "text files|TXT"
    put it into tFile
    if tFile is empty then 
        exit mouseUp
    else
        put field "fileIn" into URL ("file:" & tFile)
    end if


    see the Dictionary for other more information


3. Working With Text

    
Comments