Page 1 of 1

FileWatcher .vbs script to rename file if it exists

Posted: Wed Jun 16, 2010 6:38 am
by DataMystic Support
Save as rename_existing.vbs

Code: Select all

'FileWatcher script - rename files to .bak if they exist

Option Explicit

dim objArgs
dim fso
dim filename
dim folder

Set fso = CreateObject("Scripting.FileSystemObject")

'Set a reference to the arguments
Set objArgs = Wscript.Arguments

for each filename in objArgs

	If fso.FileExists( filename ) Then
		fso.MoveFile filename, filename & ".bak"
	End If


Set fso = Nothing
Set objArgs = Nothing
Command: C:\Windows\System32\wscript.exe
Parameters: <full path\>rename_existing.vbs %FILE%