|
-
November 28th, 1999, 11:33 PM
#1
How to detect if a directory already exists using "If" statement
How do i detect if a folder(directory) already exists using the if statement?
PanasonicSubz
-
November 28th, 1999, 11:51 PM
#2
Re: How to detect if a directory already exists using "If" statement
-
November 30th, 1999, 06:02 AM
#3
Re: How to detect if a directory already exists using "If" statement
ry an error handler on the chdir command:
Sub ChangePath( sPath as string )
on error GoTo errDir
ChDir (sPath)
Exit Sub
errDir:
If Err.Number = 76 then
MsgBox "Yep, path " + sPath + " doesn't exist"
else
MsgBox Err.Description, vbOKOnly, Err.Number
End If
End Sub
-
November 30th, 1999, 08:37 AM
#4
Re: How to detect if a directory already exists using "If" statement
Place a reference in your project to Microsoft Scripting Runtime (sscrun.dll) and use the following code :
Dim oFSO as FileSystemObject
set oFSO = new FileSystemObject
If oFSO.FolderExists("c:\temp\whatever") then
'
else
'
End If
It's probably the easiest method available, and you get a whole bunch of other functionality from using the Scripting Objects.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
December 1st, 1999, 01:19 AM
#5
Re: How to detect if a directory already exists using "If" statement
Try using the Dir function
Dir[(pathname[, attributes])]
'Variable declaration
Dim pathname as string
'Variable initialization
pathname = "Type/Retrieve directory name"
'Test existence
If (Dir(pathname, vbDirectory) <> "") then
'Directory Exists
'Dir fctn returns directory name
else
'Directory does not exist
'Dir fctn returns empty string
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|