How would i check to see if a file exits on a website before attempting to download it?
Also in my code ive enclosed the instructions in Do loop and if the file doesnt exist i want to skip the code and loop to the next file.
Printable View
How would i check to see if a file exits on a website before attempting to download it?
Also in my code ive enclosed the instructions in Do loop and if the file doesnt exist i want to skip the code and loop to the next file.
Try to navigate to that file. If the browser returns 404 - File not found, you know that the file doesn't exist. So in that case, skip to next file (put the entire block in an If...End If).
Im using a class i wrote to go through a list and download the according file but i want to check to see if the file exists first. How would i check to see if it returned a 404 error?
TRY/CATCH should return an error if it doesn't exist.
vb Code:
Do While i < 0 'code goes here Loop
Take that as an example. If i was 3 and i wanted to skip all the code on the first loop how would i do it? Like a 'next loop' kind of thing?
If you want to skipp an iteration in a loop, "Continue" is the keyword. The following code will skip 1 iteration when i = 3.
Code:
Do while i < 5
If i = 3 Then
Continue
End If
'Do your stuff here
i += 1
Loop