Você está na página 1de 2

How to check whether the given folder exists or not (in four ways) Page 1 of 2

CodeItBetter.com - Your Handy Visual Basic Source


Code Library (VB 6 Source code, Tips, Tricks,
Tutorials)
CodeItBetter.com - How to Source Code Library

Google Search

i Web n
j
k
l
m
n j codeitbetter.com
k
l
m

M
Home > How-To Library > File/Folders Handling
E
N
U
How to check whether the given folder exists or not (in four ways)

www MonsterIndia com Feedback - Ads by Google


visual basic Jobs Downloadable Macro Books Visual Basic Source Code Bridge Java and .NET
Apply for Jobs Now. Submit Your Get over 1200 Excel visual basic Find a Solution for any Support Extreme performance, trivial
Resume Free. macro examples with explanations problem Easily deployment, drop-dead easy
Monsterindia.com www.add-ins.com/macro_examples www.FixYa.com/Support/Registry www.CodeMesh.com

****************************************************************
* © 2007 CodeItBetter http://www.codeitbetter.com *
* This notice MUST stay intact for legal use *
****************************************************************

'Using Dir:

Public Function FolderExistsUsingDir(ByVal strFolder As String) As Boolean


On Error Resume Next
FolderExistsUsingDir = (Dir$(strFolder, vbDirectory) <> vbNullString)
End Function
'How can I call this function:
'Debug.Print FolderExistsUsingDir("C:\Temp\b1")

'Using FSO:

Public Function FolderExistsUsingFSO(ByVal sFolder As String) As Boolean


'Set a reference to "Microsoft Scripting Runtime"
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
FolderExistsUsingFSO = FSO.FolderExists(sFolder)
Set FSO = Nothing
End Function
'How can I call this function:
'Debug.Print FolderExistsUsingFSO("C:\Temp\b1")

'Using Attribute:

Public Function FolderExistsUsingAttrib(ByVal sFolder As String) As Boolean


Dim lRetVal As Long

On Error GoTo FileDoesntExist:


lRetVal = GetAttr(sFolder)
FolderExistsUsingAttrib = True
Exit Function

FileDoesntExist:
FolderExistsUsingAttrib = False

http://www.codeitbetter.com/programming/vb6/code/Vb6Code00046.php 19/03/2008
How to check whether the given folder exists or not (in four ways) Page 2 of 2

End Function
'How can I call this function:
'Debug.Print FolderExistsUsingAttrib("C:\Temp\b1")

'Using API:

Private Declare Function PathIsDirectory Lib "shlwapi.dll" Alias "PathIsDirectoryA" _


(ByVal pszPath As String) As Long

Public Function FolderExistsUsingAPI(ByVal sFolder As String) As Boolean


FolderExistsUsingAPI = PathIsDirectory(sFolder)
End Function
'How can I call this function:
'Debug.Print FolderExistsUsingAPI("C:\Temp\b1")

If you would like to submit your code here please email us. Do not forget to mention your name. We are always
M
thankful to each and everyone of you who submitted their code here.
E
N Source Code
Java PDF Writer for VB 40 Free .NET Controls Flow charts from C/C++
U 1-Day training on Visual
Free Create, display, print, edit, merge Advanced and Feature Easy to navigate, True-to-code
Studio 2008. Register Now! Royalty-free distribution. Try now! Complete .NET Controls by Code Metrics, beautifier, cross-ref
Microsoft.com/FirstLookClinic www.synactis.com Developer Express www.sgvsarc.com
www.devexpress.com/free

Automatic Ebay Sales Bedy Bye Bye NET TV secret pop up maker
Learn how to set up your home THE POCKET BAND IS A REGGAE NET TV is an Internet secret pop up maker you can
computer to sell your digital JAZZ ROCK SOUND LIKE television tuner program that pridict the time the pop up
products for you 24/7 with MATISYAHU, MEETS DAVE allows you to view over 1100 comes up at great little tool
out...more MATTHEWS MEETS SUBL...more online TV...more make...more

Ads by Payloadz

Join Pay-Ads.com Earn $3.5CPM


No Minimum Payout! Payouts on Every Day - E-gold and Paypal

Join Pay-ads.com Earn $3.5CPM - NO Popup ADVERTISE HERE!

Other Useful Links

z VB (Visual Basic versions 3, 4, 5 & 6)


z VB Tips & Tricks
z VB Tutorials

Bookmark us to:

Links & Support

z Essential Tools for your Windows OS


z Hosting A Website

Copyright 2006-07 codeitbetter.com | Sitemap | All rights reserved.


Email us to advertise on this site.

z Goto Top

Check this site regularly for best Visual Basic 6 resources, Source code, Tips, Tricks, Techniques, Tutorials, links,
downloads, api, and much more for the VB programmer.

http://www.codeitbetter.com/programming/vb6/code/Vb6Code00046.php 19/03/2008

Você também pode gostar