Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error - 70 with FSO causes program Crash 2

Status
Not open for further replies.

SQL2KDBA69

Programmer
Feb 4, 2004
227
US
i have a seach and copy sub but when it get an error 70 the program crash. here is the sub :


Code:
Private Sub GetFolders(Folder)
    On Error Resume Next
    
    Dim fso2
    Dim ObjFolder
    Dim colFiles
    Dim strName As String
    Dim strPath As String
    Dim strCopy As String
    
    Set fso2 = CreateObject("Scripting.FileSystemObject")
    
    For Each Subfolder In Folder.SubFolders
        If Subfolder.Path <> "C:\UserFiles" Then
                DoEvents
                Set ObjFolder = fso2.GetFolder(Subfolder.Path)
                Set colFiles = ObjFolder.Files
                For Each objfile In colFiles
                    strName = objfile.Name
                    strPath = objfile.Path
                    If Len(strName) > 3 Then
                         If Right(UCase(strName), 4) = ".DOC" Or Right(UCase(strName), 4) = ".DOCX" Or _
                            Right(UCase(strName), 4) = ".PDF" Or Right(UCase(strName), 4) = ".XLS" Then
                            DoEvents
                            strCopy = "C:\UserFiles"
                            Print #1, "Source: " & strPath & " - Destination: " & strCopy & "\" & strName
                            lb_status.Caption = "Coping - " & strPath
                            lb_status.Refresh
                            If Not fso2.FileExists(strCopy & "\" & strName) Then
                                DoEvents
                                objfile.Copy (strCopy & "\" & strName)
                                
                            End If
                        End If
                    End If
                Next
        End If
    GetFolders Subfolder
    Next    
    
End Sub
any help is appreciated.
 
If you get a runtime error 70, that would be "Permission Denied."
The reason for that, I think, could be that it tries to read the files in "C:\System Volume Information
 
what can i do to stop it from trying to read that folder?
 
You should never just put this at the top of subroutine:

Code:
On Error Resume Next

You are telling it to just keep going to the next line if there is an error. In many ways, this is much worse than the program simply crashing when it hits the error, for the following reasons:
1. You are alerted to the fact that there is a problem
2. It will likely cause further havoc throughout the program, since something was not done that probably should have been done

You should replace this with a proper error handler, something like:
Code:
On Error Goto ErrHandler

Then at the bottom something like:
Code:
  Exit Sub
 
ErrHandler:
  MsgBox "Error # " & Err.Number & ": " & Err.Description
End Sub

This will keep the program from crashing if there is an error, and will display the error to the user (who will hopefully pass it on to you).

Notice the "Exit Sub" I put above the error handler. This is to make sure the code doesn't "fall through" to the error handler when there aren't any errors.

Joe Schwarz
Custom Software Developer
 
Change
If Subfolder.Path <> "C:\UserFiles" Then
to
If Subfolder.Path <> "C:\UserFiles" and Not LCase(Subfolder.Path) = "c:\system volume information" Then

It could also be that it is trying to access other users files, which you would have to prevent as well.
 
I need it to not search the "System Volume Information:,"Local Settings" and "Windows" Directory.

would this work:

If Subfolder.Path <> "Local Settings" and Not LCase(Subfolder.Path) = "c:\windows" and Not LCase(Subfolder.Path) = "c:\system volume information" Then

 
I think either
If instr(Subfolder.Path,"Local Settings")<1 and Not LCase(Subfolder.Path) = "c:\windows" and Not LCase(Subfolder.Path) = "c:\system volume information" Then
or
If not right(lcase(Subfolder.Path),14) = "local settings" and Not LCase(Subfolder.Path) = "c:\windows" and Not LCase(Subfolder.Path) = "c:\system volume information" Then
would be better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top