Need to implement a copy folder function, the Internet to find the relevant code, and made improvements, the VBS script is as follows
Copy Code code as follows:
Dim FSO, Copycount
Set fso = CreateObject ("Scripting.FileSystemObject")
Copycount = Copycount + XCopy (FSO, ". \1", ". \2", True)
MsgBox "Copy" & Copycount & "Files!"
'********************************************************************
' * function:xcopy
'*
' * Purpose: Copy files and directory trees.
'*
' * Input:fso FileSystemObject object instance
' * source Specifies the file to copy.
' * destination Specifies the location and/or name of the new file.
' * Overwrite whether to overwrite existing files. Ture Overwrite, False skip
'*
' * Output: Returns the number of copied files
'*
'********************************************************************
Function XCopy (FSO, source, destination, overwrite)
Dim S, D, F, L, Copycount
Set s = fso. GetFolder (source)
If not FSO. FolderExists (destination) Then
Fso. CreateFolder destination
End If
Set d = fso. GetFolder (destination)
Copycount = 0
For each F in s.files
L = d.path & "\" & F.name
If not FSO. FileExists (l) Or overwrite Then
If FSO. FileExists (L) Then
Fso. DeleteFile L, True
End If
F.copy L, True
Copycount = Copycount + 1
End If
Next
For each F in s.subfolders
Copycount = Copycount + XCopy (FSO, F.path, D.path & "\" & F.name, Overwrite)
Next
XCopy = Copycount
End Function
In the script file path to create a folder, named 1, put two files, run the program results are as follows
VBS copy the code for the file:
Copy Code code as follows:
[Code]
Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
Set FN2=FSO. GetFile ("c:\index2.htm")
Flsize2=fn2.size
Fldate2=fn2.datelastmodified
Set FN=FSO. GetFile ("c:\index.htm")
Flsize1=fn.size
Fldate1=fn.datelastmodified
If FSO. FileExists ("c:\index2.htm") and flsize2>50000 and Fldate2>fldate1 Then
Fso.getfile ("c:\index2.htm"). Copy ("C:\index.htm")
If Err.number=0 then WriteHistory "Success" &now (), "Log.txt"
End If
Sub writehistory (hischars, Path)
Const ForReading = 1, ForAppending = 8
Dim FSO, F
Set fso = CreateObject ("Scripting.FileSystemObject")
Set f = fso. OpenTextFile (Path, ForAppending, True)
F.writeline Hischars
F.close
End Sub
[/code]