Jump to content
Sign in to follow this  
iHonda

_INetFileExist

Recommended Posts

iHonda

Well after searching through the help file and the forum I couldn't find anything that could check if a URL was valid, so I wrote my own function. I hope this is useful to at least one other person even though it is so simple. I was thinking about submitting it to be an included UDF but idk yet.

Without further ado or bull.. heres my function:

#cs
Name..........: _INetFileExist
Description...: Checks to see if given URL is valid
Syntax........: _INetFileExist($sUrl)
Parameters....: None
Return Values.: Success - 1
                Failure - 0
Author........: Ikaika Honda
Modified......:
Remarks.......:
Related.......:INetGetSize, FileExists
Link..........;
Example.......: Yes
#ce


Local $sUrl

Func _INetFileExist(Const $sUrl)
$size = InetGetSize($sUrl)
If $size = 0 Then
    Return(0)
Else
    Return (1)
EndIf
EndFuncoÝ÷ Ù«­¢+Ù%}%9Ñ¥±á¥ÍÐ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹ¡½¹Í¥¹Ì¹½´ÅÕ½Ðì¤Q¡¸(%5Í   ½à Ä°ÅÕ½ÐíáµÁ±ÅÕ½Ðì°ÅÕ½ÐíUI0á¥ÍÑÌÌÌìÅÕ½Ðì¤)±Í(%5Í  ½à Ä°ÅÕ½ÐíáµÁ±ÅÕ½Ðì°ÅÕ½ÐíUI0½Ì9½Ðá¥ÍÐÌÌìÅÕ½Ðì¤)¹%

edit: forgot to use the autoit tags :)

See Prog@ndy's post for a function that works with php files as well [click here]

peace,

Z

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
Xand3r

nice work :)

Local $sUrl

Func _INetFileExist(Const $sUrl)
$size = InetGetSize($sUrl)
If $size = 0 Then
    Return 0
Else
    Return $size
EndIf
EndFunc

returning the size if it is found or 0 if not is far more usefull :o

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites
iHonda

nice work :)

Local $sUrl

Func _INetFileExist(Const $sUrl)
$size = InetGetSize($sUrl)
If $size = 0 Then
    Return 0
Else
    Return $size
EndIf
EndFunc

returning the size if it is found or 0 if not is far more usefull :o

indeed it is good idea... or maybe include that as an option.. yeah.. that would be good.... i can do that thanks for the idea

@gseller: after testing the script and the INetGetSize function I discovered that INetGetSize doesn't return the size of .php extensions for some reason this could possibly take longer than expected. I'll post progress updates as progress is made.

thanks,

ihonda

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
ProgAndy

This function should work with PHP, too :)

$URL = "http://progandy.pr.funpic.de/index.php"
MsgBox(0, '', _InetFileExists($URL))
Func _InetFileExists($URL)
; -----------------------
;    by Prog@ndy
; -----------------------
    $URL = StringRegExpReplace($URL,"(.*?://)","")
    $URL = StringRegExp($URL,"\A(.*?)(?:/(.*))?\Z",3)
    If UBound($URL) = 1 Then ReDim $URL[2]
    TCPStartup()
    Local $port = StringRegExp($URL[0],":(d*)\Z",3)
    If @error Then
        $port = 80
    Else
        $port = $port[0]
        $URL[0] = StringTrimRight($URL[0],StringLen($port))
    EndIf
    Local $IP = TCPNameToIP($URL[0])
    If @error Then Return SetError(1,0,0*TCPShutdown())
    Local $conn = TCPConnect($IP,$port)
    If @error Then Return SetError(2,0,0*TCPShutdown())
    TCPSend($conn,"HEAD /" & $URL[1] & " HTTP/1.1" & @CRLF & "Host: " & $URL[0] & @CRLF& @CRLF)
    Local $recv = ""
    Do
        $recv &= TCPRecv($conn,1024)
    Until @error Or StringInStr($recv,@CRLF&@CRLF)
    TCPCloseSocket($conn)
    TCPShutdown()
    $recv = StringSplit($recv,@CRLF,1)
    If StringInStr($recv[1],"200") Then Return 1
    Return 0
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
iHonda

thanks guys guess i still need some study, thanks for solving the problem for me ProgAndy, bummers i couldn't figure it out... at least i can still claim proof of concept :) im gonna keep workin on this maybe figure a simpler way to do it


A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×