Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript FileExists

Posted on 1998-12-02
7
Medium Priority
?
1,106 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

782 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