Page 1 of 1
how to find the size of a file after answer files ?
Posted: Mon Jan 25, 2010 4:03 pm
by dme69
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.
Re: how to find the size of a file after answer files ?
Posted: Mon Jan 25, 2010 5:16 pm
by Klaus
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
Re: how to find the size of a file after answer files ?
Posted: Mon Jan 25, 2010 5:41 pm
by dme69
Thanks a lot Klaus.
I just changed "datei" by tFile in the function and all was well.
Thanks.
Dominique.
Re: how to find the size of a file after answer files ?
Posted: Mon Jan 25, 2010 5:47 pm
by Klaus
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