Solved

VBScript FileExists

Posted on 1998-12-02
7
1,061 Views
Last Modified: 2008-02-01
I want to check to see if a file on a remote directory exists using vbscript.  My code is not working
0
Comment
Question by:denam
7 Comments
 
LVL 1

Author Comment

by:denam
ID: 1447903
This is the code I'm using.  It's in an ASP file.  GetSpecialFolder(0) is tacking
C:WINNT to the front of the path.  What am I doing wrong?

<%
        Dim objFs
        Dim sFilePath

        strString = request.querystring ("att_id")
        sJPG = strString & ".jpg"
        Set objFs = CreateObject("Scripting.FileSystemObject")
        sFilePath = objFs.GetSpecialFolder(0) & "\images\members\" & sJPG

        strRequest = "Select * from Members where id = " & strString
        Set rsAtt = TIADB.Execute(strRequest)
%>
<%
       do while not rsAtt.eof

         if objFs.FileExists(sFilePath) then
           response.write ("<h3>File Path: " & sFilePath & " EXISTS</h3>")
         else
           response.write ("<h3>File Path: " & sFilePath & " NOT FOUND</h3>")
         end if
%>
0
 
LVL 1

Author Comment

by:denam
ID: 1447904
This code works - it's looking for a file on my local machine.  I just
need to figure out how to do this for a remote file.
<%      
        Dim objFs, sFilePath
        Set objFs = CreateObject("Scripting.FileSystemObject")
        sFilePath = objFs.GetSpecialFolder(0) & "\clock.avi"

         if objFs.FileExists(sFilePath) then
           response.write ("<h3>File Path: " & sFilePath & " EXISTS</h3>")
         else
           response.write ("<h3>File Path: " & sFilePath & " NOT FOUND</h3>")
         end if
%>
0
 
LVL 3

Expert Comment

by:jbil
ID: 1447905
denam

  Have you found an answer to this yet?, I've been trying to do
this also.  Thought of creating an array of files on remote that
I know are there then comparing file with that list, but I know
there has to be better way.  Thanks for any info on this.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Expert Comment

by:chabaud
ID: 1447906
What do you mean by "my code is not working" ?
Have an error message ?
How do you access to the remote computer ? (http, mapped drive, ...)
Have you got List permission on the remote computer ?

 Eloi.
0
 
LVL 3

Expert Comment

by:jbil
ID: 1447907
Speaking for myself and not denude,
I am accessing by http, with list permission by ftp.
What I'm tryng to do ,in VBscript, is when someone is on my webpage they can click to veiw imgfiles in Public dir on server(that is no problem, can do that) but want to precheck if they exist in that dir.
the "CreateObject("Scripting.FileSystemObject")" looks at the local machine not the server.
There is no error for me, function just looks in wrong place.
Thanks for any input.









0
 
LVL 1

Author Comment

by:denam
ID: 1447908
jbil, the problem you describe is exactly the problem i've encountered.
so far, I've gotten no satisfactory answer to the question.
0
 
LVL 2

Accepted Solution

by:
khaled022498 earned 100 total points
ID: 1447909
Try this code, it may help you.
regards

Function ReportFileStatus(filespec)
  Dim fso, msg
  Set fso = CreateObject("Scripting.FileSystemObject")
  If (fso.FileExists(filespec)) Then
    msg = filespec & " exists."
  Else
    msg = filespec & " doesn't exist."
  End If
  ReportFileStatus = msg
End Function


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question