How to check if a file exists, if doesn't exists, then download it?
How to check if a file exists, if doesn't exists, then download it?
Re: How to check if a file exists, if doesn't exists, then download it?
i believe it's like this.
Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo err
Dim gifbyt() As Byte
Dim i As Integer
Dim fno As Long
Inet1.Execute "http://www.codeguru.com/forum/images/cg-logo.gif", "GET"
While Inet1.StillExecuting
DoEvents
'Wait for it to stop executing
Wend
If Inet1.GetHeader("Content-length") = "" Then
MsgBox "File Not found"
Else
gifbyt() = Me.Inet1.OpenURL("http://www.codeguru.com/forum/images/cg-logo.gif", icByteArray)
'Ritrived the gif file as Bytes of Array
'Creating an empty gif file and write the bytes in to it.
fno = FreeFile()
Open "c:\logo.gif" For Binary Access Write As #fno
Put #fno, , gifbyt()
Close #fno
MsgBox "Downlod Complete"
End If
Exit Sub
err:
MsgBox err.Description
End Sub
Re: How to check if a file exists, if doesn't exists, then download it?