home *** CD-ROM | disk | FTP | other *** search
/ Club KidSoft Volume 3 #1 / ClubKidsoft.iso / movies / shared.dir / 00501_Script_501 < prev    next >
Text File  |  1995-02-08  |  2KB  |  84 lines

  1. -- FILES
  2.  
  3. on FileExists fileName
  4.   put fileio(mNew, "read", fileName) into fileObj
  5.   if objectP(fileObj) = TRUE then
  6.     fileObj(mDispose)
  7.     return TRUE
  8.   else
  9.     return FALSE
  10.   end if
  11. end
  12.  
  13. on GetFileNameFromPathName pathName
  14.   global gSep
  15.   put the number of chars of pathName into numChars
  16.   repeat with i = numChars down to 1
  17.     if char i of pathName = gSep then return char (i+1) to numChars of pathName
  18.   end repeat
  19.   return pathName
  20. end
  21.  
  22. on GetFiles pathName
  23.   put empty into theFiles
  24.   repeat with i = 1 to 10000 -- !!! assumes never more than 10000 files in a folder
  25.     put getNthFileNameInFolder(pathname, i) into n
  26.     if n = EMPTY then exit repeat
  27.     put n into line i of theFiles
  28.   end repeat
  29.   return theFiles
  30. end GetFiles
  31.  
  32. on GetPathNameFromFileName pathName
  33.   global gSep
  34.   put the number of chars of pathName - 1 into numChars -- skip last colon if there is one, assumes all names at least 1 char long
  35.   repeat with i = numChars down to 1
  36.     if char i of pathName = gSep then return char 1 to i of pathName
  37.   end repeat
  38.   return pathName
  39. end
  40.  
  41. -- NOTE: Caller must check the return value
  42. on EraseFile fileName
  43.   set file = FileIO(mNew, "read", fileName)
  44.   if not objectP(file) then 
  45.     return empty
  46.   else
  47.     put file(mDelete) into fileData
  48.     return fileData
  49.   end if
  50. end
  51.  
  52. -- NOTE: Caller must check the return value
  53. on ReadFile fileName
  54.   set file = FileIO(mNew, "read", fileName)
  55.   if not objectP(file) then 
  56.     return empty
  57.   else
  58.     put file(mReadFile) into fileData
  59.     file(mDispose)
  60.     return fileData
  61.   end if
  62. end
  63.  
  64. -- NOTE: Callers must check the return value
  65. on WriteFile fileName, data
  66.   set file = FileIO(mNew, "write", fileName)
  67.   if not objectP(file) then 
  68.     return FALSE
  69.     
  70.   else
  71.     set returnVal = TRUE
  72.     put file(mWriteString, data) into fileData -- return of 0 ==> OK 
  73.     if fileData = 0 then
  74.       put file(mSetFinderInfo, "KIDS", "????") into fileData -- return of 0 ==> OK
  75.     else
  76.       set returnVal = FALSE
  77.     end if
  78.     
  79.     file(mDispose)
  80.     return returnVal
  81.   end if
  82. end
  83.  
  84.