Results 1 to 11 of 11

Thread: [RESOLVED] File distribution script

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [RESOLVED] File distribution script

    Hi All,

    I have a File distribution script that works really well, but due to issues with Word, (our normal.dot keeps corrupting, which switching to read only fixed) but when ever I run an update and distribute it to all staff here, I can't replace a read only file. Script log says "permissions denied" re (error code 70)

    I thought that maybe adding the Script to delete the file first, then replace it with the copied version, but I'm not 100% if this script can be modified to include that.

    I could just create a short script to delete them first, then run the update, but I'd prefer to run just one.
    Code:
    Dim fso, f, fc, f1, SourceFolder
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = fso.Getfolder("D:\Folder1\Noticeboard\Normalupdates\Normal_XP\Normal.dot")
    Set f = fso.Getfolder("D:\Folder1\")
    Set fc = f.SubFolders
    For Each f1 In fc
    
    If InStr(f1.Name, ",") > 0 Then
        On Error Resume Next
            SourceFolder.Copy f1 & "\Databases\"
            If Err.Number <> 0 Then
                Select Case Err.Number    ' Evaluate error number.
                  Case 70
                    mystr = mystr & f1 & "  - Permission Denied" & vbNewLine 'add to string here
                  Case 76
                    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
    mystr = mystr & " -- File Distribution Completed -- " & vbNewLine
    Set f1 = fso.CreateTextFile("d:\Folder1\noticeboard\Update Script Logs\Normaldeletelog.txt", True)
    f1.Write mystr
    f1.Close
    Set f1 = Nothing
    Set fso = Nothing

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: File distribution script

    When you set a file Read Only, you don't have write permissions to it so you will obviously not be able to copy over it.

    Can i ask what exactly are you trying to distribute, a new Normal.dot ? and if so why ?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: File distribution script

    Yeah that right,

    I am the local systems Admin for a directorate of 130 lawyers, We use a customised Normal.dot which links into thousands of templates and a number of databases, I make regular changes to this template for updates and such like. Recently our deparetment has just be 'Upgraded' to XP from 2000, but our newly acquired OS has been locked down by the 'powers that be' and some of the customisations have had tweaks applied which inturn ask the user to save over the custom normal, which causes the occasional corruption. We've tried other methods, but read only is the old way to stop that from happening, but as I said before, it inturn created it's own little problem.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: File distribution script

    Try changing the attributes on the fly
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SetFileAttributes Lib "kernel32" Alias _
    4. "SetFileAttributesA" (ByVal lpFileName As String,_
    5. ByVal dwFileAttributes As Long) As Long
    6.  
    7.  
    8. SetFileAttributes "D:\Folder1\Noticeboard\Normalupdates\Normal_XP\Normal.dot", vbNormal
    9. 'do your copy/replace stuff here
    10. SetFileAttributes "D:\Folder1\Noticeboard\Normalupdates\Normal_XP\Normal.dot", vbReadOnly

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: File distribution script

    Thanks Hack,

    But this wouldn't change attributes of the read only file that the script is trying to save over would it?

    This would only change the read only before copying and then reapply after, is that right?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File distribution script

    looks like that is what he put,
    'do your copy/replace stuff here
    between changing the file attributes,
    though there should be no need to use the api as the inbuilt Fileattr, would also work
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: File distribution script

    I am the local systems Admin for a directorate of 130 lawyers
    I used to work for a Law firm of over 1200 people and i had a similar problem to you in fact we use to keep a whole Template Menu system in the Normal amongst other things.

    What we did to fix the issue was to move all the styles, numbering styles, macros e.t.c out of the normal.dot and into another add-in template.

    We created a separate Template document for instance called Macros.dot. We then put that template in the word Startup directory (In Word go to Tools | Options | File Locations and look for the Startup path)

    Any templates in this folder loads up when Word loads so you don't have to actually have the macros, Customised Menu's, House Styles or any other customisation actually in your Normal.dot.

    You should then be able to update you add-in template without any problems and without corrupting your normal, and you don't have to have it read only.

    I spent some time on this in the past, and you will only continue to have problems if you keep all that stuff in your normal.dot.

    You should really think hard about moving it out it will save you a lot of bother in the long run.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File distribution script

    also look into using addin workbooks (.xla)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: File distribution script

    All Sorted now, thanks..

  10. #10
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: [RESOLVED] File distribution script

    Just out of interest, what did you do to fix it ?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: [RESOLVED] File distribution script

    Went the duffus way and manually unticked every Normal.dot file, then ran the normal update.

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