All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
FSO,ASP,code,uses,File,System,Object,search,p
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,252. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Web Online Examination
By Suhas Manjunath Kashyap on 11/7


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

FileExists using the FSO

Print
Email
 
VB icon
Submitted on: 2/21/2000 1:00:00 PM
By: Joseph Hobbs 
Level: Not Given
User Rating: By 8 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 22063 times.
 
 
     This code uses the File System Object (FSO) to search and see if a particular file exists. It works both in VB and ASP (using VBSCRIPT) as expected.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: FileExists using the FSO
    ' Description:This code uses the File Sy
    '     stem Object (FSO) to search and see if a
    '     particular file exists. It works both in
    '     VB and ASP (using VBSCRIPT) as expected.
    '     
    ' By: Joseph Hobbs
    '
    ' Inputs:sFileName - the path of the fil
    '     e to check for existance
    '
    ' Returns:The function returns a boolean
    '     (true/false) value indicating whether th
    '     e file exists (true) or does not exist (
    '     false).
    '
    ' Side Effects:No side effects known
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=1632&lngWId=4    'for details.    '**************************************
    
    Public function bFileExists(sFilename As String) As Boolean
    'This function checks for the existance 
    '     of a file
    Dim fs As Object
    'Set fs to File System Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    'Check to see if file sFilename exists
    bFileExists = fs.fileexists(sFilename)
    End function

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/8/2000 3:04:34 PMLou Schilling

This pointed me to something that I had overlooked in the VBS documentation, much appreciated!!!
(If this comment was disrespectful, please report it.)

 
5/24/2000 2:06:44 PMDerek

Is there any way of using FileExists or VBscript to search for a file that is not resident on the actual Web server. I tried to use this function but it returns false if I do search outside of the Web server. Any ideas on what function I could use instead. Thanks!
(If this comment was disrespectful, please report it.)

 
3/11/2001 9:52:27 AMDeven

Even I had same problem as of Derek... The funciont returns False when tried to search files on a virtual directory which is not on the same machine as that of the IIS.
(If this comment was disrespectful, please report it.)

 
6/26/2001 6:13:51 PMconsoleWizard

This is a good use of the file system object, but be careful if you use this function in your projects. You really should release the object with a SET fs = Nothing statement.

Also take a look at the inet transfer object for looking for files on remote systems.

(If this comment was disrespectful, please report it.)

 
8/3/2001 8:54:52 AMChris

I got around the boolean result being false all the time but adding Server.Mappath to the code. For example :

bFileExists = fs.fileexists(server.mappath(sFilename))

It worked for me, give it a try !


(If this comment was disrespectful, please report it.)

 
8/18/2001 11:36:03 AMMike.h

Great code, concise and to the point. And a good demonstration of a usefull function
(If this comment was disrespectful, please report it.)

 
5/9/2002 2:10:04 PMTimmy

This thread shouldn't ever get deleted! I was troubleshooting for an hour before I gave up and started looking for something on the web. I echo Mike's thanks!
(If this comment was disrespectful, please report it.)

 
11/27/2002 10:16:55 PM

very good...u helped me a lot
(If this comment was disrespectful, please report it.)

 
2/21/2003 6:13:54 AMAsim (The Extreme Coder)

can any one tell me where to get the file system object dll ??
(If this comment was disrespectful, please report it.)

 
2/24/2003 12:41:20 PM

I triyed the code and it worked very well.
But when reloding the page several times, suddendtly, the file appears not to exist any more.
Can any one help me ?
(If this comment was disrespectful, please report it.)

 
3/12/2003 11:15:47 AMshannan leap

Worked great with the server.mappath added. Saved me alot of time troubleshooting.
(If this comment was disrespectful, please report it.)

 
4/14/2005 12:02:51 AM

I have a problem. I have the same code or syntax and I text it run the script into my computer (drive c:\) it works. The file exists method works but when I put it on a web application, it doesn't work. Does the permission involved why it didn't work or the IIS involved?
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.