VBScript Problem

Permabanned
Joined
21 Nov 2010
Posts
2,315
Location
Newton Aycliffe
Ok, so im trying to create a backup of some files from a user defined source, to a pre-defined backup folder.
If the file already exists in the backup folder, i dont want it to be backed up, but im struggling to do it.

This is what i have currently, looping through the files in the user defined source folder,checking the dates(That part is fine) and then attempting to check if it exists in the backup folder(cant seem to work out how to do it for each file, in a different directory.

Code:
For Each objfile in objFolder.Files
	if DateDiff("d", objfile.datecreated,objfile.datelastmodified) > 0 then
	
		if (Not objFSO.FileExists("C:\backup\" & objfile)) Then
			objFSO.CopyFile objfile , "c:\backup\"
			Wscript.Echo "Backing up " & Objfile
		else if objFSO.FileExists("C:\backup") Then
			Wscript.Echo objfile & " Exists, not backing up.."
		End if
	End if	
End if
Next
 
Last edited:
You want to reference the name of the file itself in a couple of places, not just the file object itself. Try this:

Code:
if (Not objFSO.FileExists("C:\backup\" & objfile.Name)) Then
	objFSO.CopyFile objfile , "c:\backup\"
	Wscript.Echo "Backing up " & objfile.Name
else if objFSO.FileExists("C:\backup") Then
	Wscript.Echo objfile.Name & " Exists, not backing up.."
end if
 
Back
Top Bottom