Get the filesize?

Shao Sean shaosean at unitz.ca
Tue Feb 5 03:42:00 EST 2002


> This looks like the ticket, Shao. Thx!
not a prob.. hope someone else finds it useful too ^_^

> I thought there might be an easier way.
mm.. there might be.. anyone? maybe the code can be cleaned up, speed up,
etc..? i know that i do a few checks to see if the file really does exist,
but that's okay.. doesn't seem to be slow at all..

> BTW, I think I'll insert a put the defaultFolder into oldDefaultFolder
> before changing it, that way I can restore it at the end.
store the original default folder before calling this function and then
restore it after calling it.. or use this modified code..


-- Start code --
function getFileSize pFullFilePath
  # Declare the variables
  local vFilePath, vFileName, vDirectoryListing, vDirectoryListingLine,
vOriginalDirectory -- CHANGE: added the vOriginalDirectory variable

  # Store the current default directory
  put the defaultFolder into vOriginalDirectory  -- CHANGE: added this line

  # Split the file's path and name
  set the itemDelimiter to "/"
  put the last item of pFullFilePath into vFileName
  put pFullFilePath into vFilePath
  delete last item of vFilePath
  set the itemDelimiter to comma

  # Change the directory
  set the defaultFolder to vFilePath

  # Get the directory listing
  put the detailed files into vDirectoryListing

  # Find our file and return the file size
  if (vFileName is among the items of vDirectoryListing) then
    repeat for each line vDirectoryListingLine in vDirectoryListing
      if (item 1 of vDirectoryListingLine = vFileName) then
        set the defaultFolder to vOriginalDirectory  -- CHANGE: added this
line
        if (the platform is "MacOS") then
          return item 2 of vDirectoryListingLine + item 3 of
vDirectoryListingLine
        else
          return item 2 of vDirectoryListingLine
        end if
      end if
    end repeat
  else
    return -1
  end if
end getFileSize
-- End Code --






More information about the use-livecode mailing list