Results 1 to 9 of 9

Thread: Path Unreachable Check

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Location
    Atlanta, GA
    Posts
    34

    Path Unreachable Check

    I'm writing a utility with VB.NET that pushes out new files to several locations. I'm reading in all of the locations from an INI file, but sometimes the computer might be turned off for one of my target locations. How can I check to see if the target (ie. target1=\\computer1\targetdirectory\) is reachable before copying the file? I can't seem to find a Path.Exists method or anything similar. Maybe I'm just missing it.
    MHC_Craig

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Path Unreachable Check

    You may want to try creating a temp file in that path and then use the file exists method to double check it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Path Unreachable Check

    VB Code:
    1. if System.IO.Directory.Exists("\\computer1\targetdirectory\") then
    2.     'copy file
    3. else
    4.     'dir doesnt exist
    5. end if

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Path Unreachable Check

    Nice, kleinma. Show me up as usual

    Your way is good but my way will make sure the files can be copied over to
    in case of any permission issues.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Path Unreachable Check

    Quote Originally Posted by RobDog888
    Nice, kleinma. Show me up as usual

    Your way is good but my way will make sure the files can be copied over to
    in case of any permission issues.

    true... but technically if I was coding this, I would check for the path to exist. if it does, then I would do the file copy in try/catch blocks, which would handle any issue like permissions...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Path Unreachable Check

    I think I'm having one of "those" days

    Yet again, you have the best solution.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Path Unreachable Check

    Quote Originally Posted by RobDog888
    I think I'm having one of "those" days

    Yet again, you have the best solution.
    its ok rob.. you just have a case of the user control blues

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Path Unreachable Check

    Actually I am feeling good today because I got my car back with new tires on the rear. Now I can
    go back to racing all those punks that think they are faster then me with their little
    import toy racer cars

    But I do have a new thread on my UC. Its a small question.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2004
    Location
    Atlanta, GA
    Posts
    34

    Re: Path Unreachable Check [RESOLVED]

    Quote Originally Posted by kleinma
    true... but technically if I was coding this, I would check for the path to exist. if it does, then I would do the file copy in try/catch blocks, which would handle any issue like permissions...
    Here's what I have working with the exception of permissions problems.
    Permissions problems are what I'm dealing with now. I'll put in the try/catch. Thanks...

    VB Code:
    1. If Directory.Exists(target) Then
    2.                             If File.Exists(copytarget) Then
    3.                                 File.Delete(copytarget)
    4.                             End If
    5.                             'don't copy *.scc files
    6.                             Dim extcheck() As String = Split(xFiles(y), ".")
    7.                             If Directory.Exists(target) Then
    8.                                 If UCase(extcheck(UBound(extcheck))) <> "SCC" Then
    9.                                     writelog.WriteLine(ControlChars.Tab & copytarget)
    10.                                     File.Copy(copysource, copytarget)
    11.                                 End If
    12.                             Else
    13.                                 writelog.WriteLine("*************************************")
    14.                                 writelog.WriteLine("** Could not reach " & copytarget)
    15.                                 writelog.WriteLine("*************************************")
    16.                             End If
    17.                         Else
    18.                             Dim detailmsg As String = "*************************************" & _
    19.                                                       vbCrLf & "** Could not reach " & target & _
    20.                                                       vbCrLf & "*************************************"
    21.                             writelog.WriteLine(detailmsg)
    22.                          End If
    MHC_Craig

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