Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBScript FileExists

Posted on 1998-12-02
7
1,065 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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