Solved

VBScript FileExists

Posted on 1998-12-02
7
1,053 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:chabaud
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now