~siggi-bjarnason/siggivbscript/vbscript

1 by Siggi Bjarnason
initial add
1
Option Explicit
2
Dim fso,srcFile,dstFile,f,BaseName,dtCreated,CreatedDate,strExt
3
Set fso = CreateObject("Scripting.FileSystemObject")
4
If wscript.arguments.count > 1 Then
5
	srcFile = wscript.arguments(0)
6
	dstFile = wscript.arguments(1)
7
Else
8
	wscript.echo "Need two parameters, source file path/name and destination path"
9
	wscript.quit
10
End If 
11
If not fso.fileexists(srcFile) Then
12
	wscript.echo "Source file," & srcFile & ", not found"
13
	wscript.quit
14
End If
15
If not fso.folderexists(dstfile) Then
16
	wscript.echo "Destination path does not exists, please specify a valid path"
17
	wscript.quit
18
End If 
19
Set f = fso.GetFile(srcFile)
20
CreatedDate = f.DateLastModified
21
BaseName = fso.GetBaseName(srcFile)
22
strExt = fso.GetExtensionName(srcFile)
23
dtCreated = DatePart("m",CreatedDate) & "-" & DatePart("d",CreatedDate) & _
24
			 "-" & DatePart("yyyy",createddate)
25
dstfile = fso.buildpath(dstfile, BaseName & dtCreated & "." & strExt)
26
wscript.echo "copy " & srcfile & " " & dstfile & " /y"
27
fso.copyfile srcfile, dstfile, true
28
If fso.fileexists(dstfile) Then
29
	wscript.echo "copy successful"
30
Else
31
	wscript.echo "copy failed"
32
End If
33
34
35