会社のコンピュータ上のソフトウェアを同期させます.vbs.

2576 ワード

05~06年に書いたものを上に置いて、バックアップをとってみましょう.今見てみます.あの時書いたコードは、やはり規範的です.
今なら、javascriptかpythonで書いてみます.
Option Explicit
'------------------------------------------------------------
'  :               
'------------------------------------------------------------
'Const strFolderA = "G:\Downloads\Soft"
'Const strFolderB = "K:\Soft"

Const strFolderB = "G:\Downloads\Soft"
Const strFolderA = "K:\Soft"

Dim fsoObj
Set fsoObj = CreateObject("Scripting.FileSystemObject")

If Not fsoObj.FolderExists(strFolderA) Then 
	MsgBox("   " & strFolderA & "   !")
Else
	If Not fsoObj.FolderExists(strFolderB) Then fsoObj.CreateFolder(strFolderB)
	Synchronize strFolderA, strFolderB
End If
Set fsoObj = Nothing
MsgBox("  ,    !")

'------------------------------------------------------------
'  :       
'  :
'	  sFolderA        
'     sFolderB        
'  : 
'------------------------------------------------------------
Sub Synchronize(sFolderA, sFolderB)
	Dim fsoFolderA,fsoFolderB
	Dim fsoSubFolderA, fsoSubFolderB
	Dim itmFolderA,itmFolderB
	Dim fsoFileA,fsoFileB
	Dim itmFileA,itmFileB
	Dim blnFileInFolderB
	Dim blnFolderInFolderB

	Set fsoFolderA = fsoObj.GetFolder(sFolderA)
	Set fsoFolderB = fsoObj.GetFolder(sFolderB)
	Set fsoFileA = fsoFolderA.Files
	Set fsoFileB = fsoFolderB.Files

	For Each itmFileA In fsoFileA
		blnFileInFolderB = False
		For Each itmFileB In fsoFileB
			If itmFileA.Name = itmFileB.Name And _
			   itmFileA.Size = itmFileB.Size And _
			   itmFileA.DateLastModified = itmFileB.DateLastModified Then
			   blnFileInFolderB = True
			   Exit For
			End If
		Next

		If Not blnFileInFolderB Then
			itmFileA.Copy fsoFolderB.path & "\" & itmFileA.Name, True
		End If
	Next
	Set fsoFileA = Nothing
	Set fsoFileB = Nothing

	Set fsoSubFolderA = fsoFolderA.SubFolders
	Set fsoSubFolderB = fsoFolderB.SubFolders
	For Each itmFolderA In fsoSubFolderA
		blnFolderInFolderB = False
		For Each itmFolderB In fsoSubFolderB
			If itmFolderA.Name = itmFolderB.Name Then
				blnFolderInFolderB = True
				Exit For
			End If
		Next
		If Not blnFolderInFolderB Then
			fsoObj.CreateFolder(fsoFolderB.path & "\" & itmFolderA.Name)
		End If
		Synchronize itmFolderA.Path, Replace(itmFolderA.Path,strFolderA,strFolderB)
	Next

	Set fsoSubFolderA = Nothing
	Set fsoSubFolderB = Nothing
	Set fsoFolderA = Nothing
	Set fsoFolderB = Nothing
End Sub
原文のリンク:http://blog.csdn.net/kimsoft/article/details/6783838