Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21089

How to monitor if file exists remotely via UNC?

$
0
0
I'm trying to monitor if a folder exists on a remote system by checking to see if a file exists in it. I have a batch file in the background that makes a network connection with user/pass so when I type in \\SERVER\FOLDER\file.txt in the Windows RUN command, i'm able to open the file directly. But when I try see if the file exists via VB i'm not successful.

Here is one code i tried.

Code:

Private Sub Command1_Click()

    Dim fso As FileSystemObject
    Set fso = New FileSystemObject
   
    MsgBox fso.FileExists("//SERVER/c$/test/test.txt")
    MsgBox fso.FileExists("\\SERVER\c$\test\test.txt")
     
End Sub

Second code i tried, it works locally, but not when using UNC.

Code:

Dim fso As FileSystemObject
Dim sFilePath As String
 
    Set fso = New FileSystemObject
 
    sFilePath = "c:\setup.log"
    If fso.FileExists(sFilePath) Then
        MsgBox "File Exist."
    Else
        MsgBox "File Doesn't Exist."
    End If

I read somewhere that maybe UNC codes can't be used, but then I see others posting that it does work. I am trying to connect with C$ hidden folders, could that be the issue? I have full admin rights, i'm able to get the code to work locally on my system, but not when using mapped drives or UNC codes.

Viewing all articles
Browse latest Browse all 21089

Trending Articles