|
-
Nov 16th, 2009, 07:20 AM
#1
Thread Starter
Lively Member
[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
-
Nov 16th, 2009, 09:28 AM
#2
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
-
Nov 16th, 2009, 09:59 AM
#3
Thread Starter
Lively Member
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.
-
Nov 16th, 2009, 12:00 PM
#4
Re: File distribution script
Try changing the attributes on the fly
vb Code:
Option Explicit
Private Declare Function SetFileAttributes Lib "kernel32" Alias _
"SetFileAttributesA" (ByVal lpFileName As String,_
ByVal dwFileAttributes As Long) As Long
SetFileAttributes "D:\Folder1\Noticeboard\Normalupdates\Normal_XP\Normal.dot", vbNormal
'do your copy/replace stuff here
SetFileAttributes "D:\Folder1\Noticeboard\Normalupdates\Normal_XP\Normal.dot", vbReadOnly
-
Nov 16th, 2009, 12:14 PM
#5
Thread Starter
Lively Member
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?
-
Nov 16th, 2009, 03:22 PM
#6
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
-
Nov 17th, 2009, 07:18 AM
#7
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
-
Nov 18th, 2009, 02:33 AM
#8
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
-
Nov 19th, 2009, 05:25 AM
#9
Thread Starter
Lively Member
Re: File distribution script
-
Nov 19th, 2009, 06:22 AM
#10
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
-
Nov 19th, 2009, 09:02 AM
#11
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|