FileWatcher .vbs script to rename file if it exists

Discuss our other products here. Get help with installation and running, notify us of bugs, request new features and enhancements.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

FileWatcher .vbs script to rename file if it exists

Post 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

next

Set fso = Nothing
Set objArgs = Nothing
Command: C:\Windows\System32\wscript.exe
Parameters: <full path\>rename_existing.vbs %FILE%
Attachments
rename files if they exist.zip
(406 Bytes) Downloaded 1513 times
Post Reply