Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IntGetFileSize
#1
I'm trying:

Macro Macro22
Code:
Copy      Help
str f="http://download.kiwix.org/portable/wikipedia_es_all.zip"
out IntGetFileSize(f)

Error (RT) in Macro22: unknown size.

Is there another way?
#2
Because file size was more than int range. This version supports any file size. Returns long, not int.

Function IntGetFileSize
Code:
Copy      Help
;/
function'long $url [inetflags]

;Returns internet file size.

;url - file URL.
;inetflags - optional dwFlags argument for InternetOpenUrl API.

;REMARKS
;Sends request to download the file, but gets only response headers, not whole file.
;Error if fails, or if file size is not specified in response headers (no Content-Length header).


#opt nowarnings 1
Http http
__HInternet hi=InternetOpenUrl(http.hinternet(1) url 0 0 inetflags 0); if(!hi) end "failed"
_s.all(30); _i=30
if(!HttpQueryInfo(hi HTTP_QUERY_CONTENT_LENGTH _s &_i 0)) end "unknown size"
ret val(_s.fix 1)
#3
Thanks.

Is possible to get 'Last modified' of file?
#4
Function IntGetLastModified
Code:
Copy      Help
;/
function'DateTime $url [inetflags]  ;;flags: convert UTC/GMT to local time

;Returns internet file Last-Modified date.

;url - file URL.
;inetflags - optional dwFlags argument for InternetOpenUrl API.

;REMARKS
;Sends request to download the file, but gets only response headers, not whole file.
;Error if fails, or if there is no Last-Modified header.
;The date is in GMT time zone, which is the same as UTC. Use UtcToLocal if need your local time, see example.

;EXAMPLE
;DateTime t=IntGetLastModified("http://www.quickmacros.com/support.html")
;t.UtcToLocal
;out t.ToStr


#opt nowarnings 1
Http http
__HInternet hi=InternetOpenUrl(http.hinternet(1) url 0 0 inetflags 0); if(!hi) end "failed"
SYSTEMTIME st; _i=sizeof(st)
if(!HttpQueryInfo(hi HTTP_QUERY_LAST_MODIFIED|HTTP_QUERY_FLAG_SYSTEMTIME &st &_i 0)) end "unknown Last-Modified"
DateTime r.FromSYSTEMTIME(st)
ret r
Function IntGetLastModifiedString
Code:
Copy      Help
;/
function'str $url [inetflags]

;Returns internet file Last-Modified date as raw header string.

;url - file URL.
;inetflags - optional dwFlags argument for InternetOpenUrl API.

;REMARKS
;Sends request to download the file, but gets only response headers, not whole file.
;Error if fails, or if there is no Last-Modified header.


#opt nowarnings 1
Http http
__HInternet hi=InternetOpenUrl(http.hinternet(1) url 0 0 inetflags 0); if(!hi) end "failed"
_s.all(300); _i=300
if(!HttpQueryInfo(hi HTTP_QUERY_LAST_MODIFIED _s &_i 0)) end "unknown Last-Modified"
ret _s.fix
#5
Perfect!.
Thanks again.


Forum Jump:


Users browsing this thread: 1 Guest(s)