I have a situation where I need to replace files on a PC only if they exist.
eg
we have a program (old access program accessing SQL DBs!) that has login permissions controlled by the actual startup file. If you need more permissions you need a different startup file.
These files have the DB name hardcoded and we have now decided to move the DB to a new server and give it a more relivent name but this means changing every single startup file on every persons PC. The issue here is that depending on what permissions they have depends on what file they need replacing.
I need a script that can read from a text file a list of file names, and then only if the user already has that file copy the new one over the top.
up to now I have managed to sort the If the file already exists copy over the top if not do nothing side of the script and created a file to check for to stop the script applying over and over again on each login
But the above code only works for single files. Can any one help me intergrate and read from text file for file name into this?
Thanks
eg
we have a program (old access program accessing SQL DBs!) that has login permissions controlled by the actual startup file. If you need more permissions you need a different startup file.
These files have the DB name hardcoded and we have now decided to move the DB to a new server and give it a more relivent name but this means changing every single startup file on every persons PC. The issue here is that depending on what permissions they have depends on what file they need replacing.
I need a script that can read from a text file a list of file names, and then only if the user already has that file copy the new one over the top.
up to now I have managed to sort the If the file already exists copy over the top if not do nothing side of the script and created a file to check for to stop the script applying over and over again on each login
Code:
'Set Dimension
DIM fso
'Set Object
Set fso = CreateObject("Scripting.FileSystemObject")
'Create Condition
If (fso.FileExists("c:\destfolder\donotdelete.txt")) Then
WScript.Quit()
Else
Const DestinationFile = "c:\destfolder\anyfile.txt"
Const SourceFile = "c:\sourcefolder\anyfile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
'Check to see if the file already exists in the destination folder
If fso.FileExists(DestinationFile) Then
'Check to see if the file is read-only
If Not fso.GetFile(DestinationFile).Attributes And 1 Then
'The file exists and is not read-only. Safe to replace the file.
fso.CopyFile SourceFile, "C:\destfolder\", True
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\destfolder\donotdelete.txt", True)
Else
'The file exists and is read-only.
'Remove the read-only attribute
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
'Replace the file
fso.CopyFile SourceFile, "C:\destfolder\", True
'Reapply the read-only attribute
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\destfolder\donotdelete.txt", True)
End If
Else
End If
Set fso = Nothing
end if
But the above code only works for single files. Can any one help me intergrate and read from text file for file name into this?
Thanks
Last edited: