Results 1 to 3 of 3

Thread: [RESOLVED] Not sure what I'm doing wrong....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [RESOLVED] Not sure what I'm doing wrong....

    The Attached script is designed to copy a single file and distribute it to many different directories on a shared folder, It works fine, although I've come across a couple of errors that I would like to log, the first one is error 76 "File path not found" and the other is error 70 "Permission Denied".

    The problem I'm getting is that everytime the script runs it records both errors for the same problem. IE:

    K:\Named, Folder\Test Area\ZZZ, Okay2 - Permission Denied
    K:\Named, Folder\Test Area\ZZZ, Okay2 - Path not found
    K:\Named, Folder\Test Area\ZZZ, Okay3 - Permission Denied
    K:\Named, Folder\Test Area\ZZZ, Okay3 - Path not found

    Not sure is that is the nature of both Errors or the fact the script is written wrong.


    Code:
    Dim fso, f, fc, f1, SourceFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SourceFile = fso.Getfile("K:\Noticeboard\Normalupdates\Normal\Normal.dot")
    Set f = fso.GetFolder("K:\Named, Folder\Test Area")
    Set fc = f.SubFolders
    For Each f1 In fc
    
    If InStr(f1.Name, ",") > 0 Then
        On Error Resume Next
            SourceFile.Copy f1 & "\Databases\Normal\"
            If Err.Number <> 0 Then
                Select Case Err.Number    ' Evaluate error number.
                    Case 70  ' "Permission Denied" error.
                    Case 76  ' "Path not found" error.
                     mystr = mystr & f1 & "  - Permission Denied" & vbNewLine 'add to string here
                     mystr = mystr & f1 & "  - Path not found" & vbNewLine ' add to string here
                    Err.Clear
                    Case Else
                        End Select
            Else
            End If
            On Error GoTo 0
    End If
    Next
    
    Set f1 = fso.CreateTextFile("K:\Named, Folder\Test Area\ScriptLog.txt", True)
    f1.Write mystr
    f1.Close
    Set f1 = Nothing
    Set fso = Nothing
    Any help would be greatly appriciated

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Not sure what I'm doing wrong....

    You only log for error 76 not 70, since there is no code written for Case 70. Select Case works differently then for example switch in C. What you should do is to change your code to look simular to this:
    Code:
    Select Case Err.Number
        Case 70
            mystr = mystr & f1 & "  - Permission Denied" & vbNewLine
        Case 76
            mystr = mystr & f1 & "  - Path not found" & vbNewLine
        Case Else
    End Select
    Err.Clear

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Not sure what I'm doing wrong....

    Many thanks, the code work great now, Your a star!

    Just a quick question though,

    Under this command "SourceFile.Copy f1 & "\Databases\Normal\"" could I also tell the script to skip recording any file under under File path "Databases\Normal_PM" IE: - If File path "Databases\Normal_PM" Resume next.

    Reason is, throughout the shared folder, there is a mix of different Normal.dot templates, some get one and some get another. We differinciate between each user by having a folder in each users directory called either 'Normal' or 'Normal_PM'.

    The script picks up the file path as Not found if the file path is wrong, I would prefer the script to pick up a fault rather then the normal runnings.
    Last edited by Kubull; Feb 1st, 2008 at 11:08 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width