Home > Archive > Visual Basic > October 2005 > Folder/Drive existance
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Folder/Drive existance
|
|
|
| Hello,
Currently, I am using FileSystemObject to check the existance of a specific
folder (or drive). The functions I'm using are
objectname.FolderExist(folderpath)
objectname.DriveExist(drivename)
Because I frequently excounter problems with ScrRun.DLL, I want to use some
API to replace these two functions. Can anyone tell me how to do that? (which
API can be used?)
Thanks.
| |
| Bob Butler 2005-10-28, 6:55 pm |
| "Wyne" <Wyne@discussions.microsoft.com> wrote in message news:050C653B-
DC8B-45A1-8394-158B4E5FA702@microsoft.com
> Hello,
>
> Currently, I am using FileSystemObject to check the existance of a
> specific folder (or drive). The functions I'm using are
>
> objectname.FolderExist(folderpath)
> objectname.DriveExist(drivename)
>
> Because I frequently excounter problems with ScrRun.DLL, I want to
> use some API to replace these two functions. Can anyone tell me how
> to do that? (which API can be used?)
no need for an API... use the GetAttr function and trap the error
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Matt Williamson 2005-10-28, 6:55 pm |
| Wyne-
Here are the functions that I use and I've never had a problem.
'-----------------------------------------------------------
' FUNCTION: DirExists
' Determines whether the specified directory name exists.
' IN: [sDirName] - name of directory to check for
' Returns: True if the directory exists, False otherwise
'-----------------------------------------------------------
Public Function DirExists(ByVal sDirName As String) As Boolean
On Error Resume Next
DirExists = (GetAttr(sDirName) And vbDirectory) = vbDirectory
On Error GoTo 0
End Function
'-----------------------------------------------------------
' FUNCTION: FileExists
' Determines whether the specified file exists
' IN: [sPathName] - file to check for
' Returns: True if file exists, False otherwise
'-----------------------------------------------------------
Public Function FileExists(ByVal sPathName As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sPathName) And vbNormal) = vbNormal
On Error GoTo 0
End Function
HTH
Matt
"Wyne" <Wyne@discussions.microsoft.com> wrote in message
news:050C653B-DC8B-45A1-8394-158B4E5FA702@microsoft.com...
> Hello,
>
> Currently, I am using FileSystemObject to check the existance of a
> specific
> folder (or drive). The functions I'm using are
>
> objectname.FolderExist(folderpath)
> objectname.DriveExist(drivename)
>
> Because I frequently excounter problems with ScrRun.DLL, I want to use
> some
> API to replace these two functions. Can anyone tell me how to do that?
> (which
> API can be used?)
>
>
> Thanks.
>
| |
| Tony Proctor 2005-10-29, 7:55 am |
| You have a small problem in your FileExists function Matt. vbNormal is
defined as 0. Hence (GetAttr(sPathName) And vbNormal) will *always* evaluate
to 0, irrespective of what's returned by GetAttr. In other words, the bit
test isn't doing anything useful, and FileExists would return True even if
applied to a directory.
Here's the equivalent functions I use:
Public Function bDirExists(sDir As String) As Boolean
On Error Resume Next
bDirExists = ((GetAttr(sDir) And vbDirectory) <> 0)
End Function
Public Function bFileExists(sFile As String) As Boolean
On Error Resume Next
bFileExists = ((GetAttr(sFile) And vbDirectory) = 0)
End Function
Tony Proctor
"Matt Williamson" <ih8spam@spamsux.org> wrote in message
news:u9FgoI82FHA.3976@TK2MSFTNGP15.phx.gbl...
> Wyne-
>
> Here are the functions that I use and I've never had a problem.
>
> '-----------------------------------------------------------
> ' FUNCTION: DirExists
> ' Determines whether the specified directory name exists.
> ' IN: [sDirName] - name of directory to check for
> ' Returns: True if the directory exists, False otherwise
> '-----------------------------------------------------------
> Public Function DirExists(ByVal sDirName As String) As Boolean
> On Error Resume Next
> DirExists = (GetAttr(sDirName) And vbDirectory) = vbDirectory
> On Error GoTo 0
> End Function
>
> '-----------------------------------------------------------
> ' FUNCTION: FileExists
> ' Determines whether the specified file exists
> ' IN: [sPathName] - file to check for
> ' Returns: True if file exists, False otherwise
> '-----------------------------------------------------------
> Public Function FileExists(ByVal sPathName As String) As Boolean
> On Error Resume Next
> FileExists = (GetAttr(sPathName) And vbNormal) = vbNormal
> On Error GoTo 0
> End Function
>
>
> HTH
>
> Matt
> "Wyne" <Wyne@discussions.microsoft.com> wrote in message
> news:050C653B-DC8B-45A1-8394-158B4E5FA702@microsoft.com...
>
>
|
|
|
|
|