Results 1 to 7 of 7

Thread: [RESOLVED] Check for file on web and Also exit a loop

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Resolved [RESOLVED] Check for file on web and Also exit a loop

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Check for file on web and Also exit a loop

    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).
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: Check for file on web and Also exit a loop

    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?
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564

    Re: Check for file on web and Also exit a loop

    TRY/CATCH should return an error if it doesn't exist.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: Check for file on web and Also exit a loop

    Quote Originally Posted by BrianS View Post
    TRY/CATCH should return an error if it doesn't exist.
    I know of that method also but thats not my main issue here. Im trying to figure out how to continue looping even though the exception is being thrown and until it finishes looping then it exits.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: Check for file on web and Also exit a loop

    vb Code:
    1. Do While i < 0
    2.             'code goes here
    3.         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?
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Check for file on web and Also exit a loop

    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
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width