how to find the size of a file after answer files ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dme69
Posts: 22
Joined: Sat Nov 14, 2009 5:57 pm

how to find the size of a file after answer files ?

Post by dme69 » Mon Jan 25, 2010 4:03 pm

Hello,

All is in the title ... ;-)

I want to select some files like this :

Code: Select all

answer files "Select a file to upload" with type filtreFtp
and I want to limit the selection by size too. It can be a solution for me to have the size of selected files just after "answer files" ...

I hope someone will be able to help me.
Best to all.

Dominique.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to find the size of a file after answer files ?

Post by Klaus » Mon Jan 25, 2010 5:16 pm

Bonjour Dominique,

here is a little function I use in my projects.
The path to the file is the parameter and will return the size of this file in Bytes:

Code: Select all

function tFileSize tFile
    set itemdel to "/"
    put the directory into altdir

   ## Get the necessary infos from the path
    put item 1 to -2 of datei into tFolder
    put item -1 of datei into tFilename

   ## Set the directory to the folder that has the file inside
    set the directory to tFolder

    ## Check "the long (detailed) files" in the Rev dictionary!
    put the long files into tlf
    put lineoffset(urlencode(tFilename),tlf) into tLine
    set itemdel to ","
    put item 2 of line tLine of tlf into tSize

    ## RESET the directory!
    set the directory to altdir

   ## Size in Bytes
    return tSize
end tFileSize
Use it like this:

Code: Select all

...
answer files "Select a file to upload" with type filtreFtp
put it into tFile
if tFile is not empty then
  put tFileSize(tFile) into tFileSize2

  ## now check tFileSize2 and act accordingly...
end if
...
Best

Klaus

dme69
Posts: 22
Joined: Sat Nov 14, 2009 5:57 pm

Re: how to find the size of a file after answer files ?

Post by dme69 » Mon Jan 25, 2010 5:41 pm

Thanks a lot Klaus.

I just changed "datei" by tFile in the function and all was well.

Thanks.
Dominique.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to find the size of a file after answer files ?

Post by Klaus » Mon Jan 25, 2010 5:47 pm

Hi Dominique,

ah, yes, sorry, I tend to always use german names and quickly translated my function, but overlooked some occurencies "datei" (= file = fichier) :)
Glad It works for you!

OK, for the rest, here is the corrected function:

Code: Select all

function tFileSize tFile
    set itemdel to "/"
    put the directory into altdir

   ## Get the necessary infos from the path
    put item 1 to -2 of tFile into tFolder
    put item -1 of tFile into tFilename

   ## Set the directory to the folder that has the file inside
    set the directory to tFolder

    ## Check "the long (detailed) files" in the Rev dictionary!
    put the long files into tlf
    put lineoffset(urlencode(tFilename),tlf) into tLine
    set itemdel to ","
    put item 2 of line tLine of tlf into tSize

    ## RESET the directory!
    set the directory to altdir

   ## Size in Bytes
    return tSize
end tFileSize
Best

Klaus

Post Reply