Link to home
Start Free TrialLog in
Avatar of MOQINFRA
MOQINFRA

asked on

Copy a file after renaming another file

I need to replace a file named file.xml for all users on the computer remotely
The file is located at this location and needs to be replaced by finenew.xml

C:\Users\abcuser\AppData\Local\App01\file.xml

however i do not want to delete the filr.xml instead need to rename it to fileold.xml and keep it at the same location

So if the file exists the scripts should run and replace it with mu new file and rename the old file
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, this VBS implemented as a login script should work for you.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strFileToReplace = objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\App01\File.xml"
strBackupFile = objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\App01\File.xml.old"
strNewFile = "\\server\share\newfile.xml"
If objFSO.FileExists(strBackupFile) = False Then
	If objFSO.FileExists(strFileToReplace) = True Then
		objFSO.CopyFile strFileToReplace, strBackupFile, True
		objFSO.CopyFile strNewFile, strFileToReplace, True
	End If
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Faustulus
Faustulus
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MOQINFRA
MOQINFRA

ASKER

Thanks , will test it and update you guys