|
-
Mar 31st, 2000, 04:18 AM
#1
Thread Starter
Member
For the code below where would I put an Else statement if the file was not found.
Private Sub Command1_Click()
Set m_objFSO = New Scripting.FileSystemObject
Screen.MousePointer = vbHourglass
Call CheckFolder("C:\")
Screen.MousePointer = vbDefault
End Sub
Public Sub CheckFolder(sPath As String)
Dim objFolder As Scripting.Folder
Dim objSubDirs As Scripting.Folders
Dim objLoopFolder As Scripting.Folder
Dim myItem As String
Dim res As String
m_objFSO.FileExists = False
Set objFolder = m_objFSO.GetFolder(sPath)
'Does the sPath string require an extra back-slash?
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
If (m_objFSO.FileExists(sPath & "AcroRd32.exe")) Then
ShellExecute 0&, "OPEN, App.Path & "P:\EngineModelProject\16CM32HFO\16CM32HFOManHours.pdf", "", "", 1
End If
Set objSubDirs = objFolder.SubFolders
'Repeat this Sub for each sub directory in
'the SubFolders collection
For Each objLoopFolder In objSubDirs
CheckFolder objLoopFolder.Path
Next objLoopFolder
'Free up memory
Set objSubDirs = Nothing
Set objFolder = Nothing
End Sub
-
Mar 31st, 2000, 04:31 AM
#2
Frenzied Member
Just before your End If put an Exit Sub Command, then just before you destroy your scripting objects put the code for not finding the file, Like this
Code:
Private Sub Command1_Click()
Set m_objFSO = New Scripting.FileSystemObject
Screen.MousePointer = vbHourglass
Call CheckFolder("C:\")
Screen.MousePointer = vbDefault
End Sub
Public Sub CheckFolder(sPath As String)
Dim objFolder As Scripting.Folder
Dim objSubDirs As Scripting.Folders
Dim objLoopFolder As Scripting.Folder
Dim myItem As String
Dim res As String
m_objFSO.FileExists = False
Set objFolder = m_objFSO.GetFolder(sPath)
'Does the sPath string require an extra back-slash?
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
If (m_objFSO.FileExists(sPath & "AcroRd32.exe")) Then
ShellExecute 0&, "OPEN, App.Path & "P:\EngineModelProject\16CM32HFO\16CM32HFOManHours.pdf", "", "", 1
' *
' *
Exit Sub '****************** LOOK
' *
' *
End If
Set objSubDirs = objFolder.SubFolders
'Repeat this Sub for each sub directory in
'the SubFolders collection
For Each objLoopFolder In objSubDirs
CheckFolder objLoopFolder.Path
Next objLoopFolder
' ******************************
' *Put File not found code Here*
' ******************************
'Free up memory
Set objSubDirs = Nothing
Set objFolder = Nothing
End Sub
Hope this helps
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
|