home *** CD-ROM | disk | FTP | other *** search
- '--------------------------------------------------------------------------
- ' SafeCopy.vbs - Makes backup copy of the VisualC project tree.
- ' Backup copy is copied to the first removable drive.
- ' Assumes that WinZip is installed.
- ' To customize this script, change constants
- ' specified at the top of the file.
- '
- ' NOTE: Before running this script make sure that folder
- ' specified in sRootFolder variable is current folder.
- '
- ' This file is part of the sgFileSys.
- ' Copyright (C) 1998 Stinga
- ' You can use and modify this script.
- '--------------------------------------------------------------------------option explicit
- option explicit
-
- Dim sRootFolder, sProjectFolder, sZipFile
- sRootFolder = "f:/Projects/"
- sProjectFolder = "f:/Projects/Components/sgFileSys/"
- sZipFile = "sgFileSys"
-
-
- ' SGFileSys.Enumerator constants
- const sgfAll = &H00001FF7&
- const sgfArchive = &H00000020&
- const sgfCompressed = &H00000800&
- const sgfDirectory = &H00000010&
- const sgfEncrypted = &H00000040&
- const sgfHidden = &H00000002&
- const sgfNormal = &H00000080&
- const sgfOffline = &H00001000&
- const sgfReadOnly = &H00000001&
- const sgfReparsePoint = &H00000400&
- const sgfSparseFile = &H00000200&
- const sgfSystem = &H00000004&
- const sgfTemporary = &H00000100&
-
-
- ' Create and initialize file enumerator
- Dim en
- Set en = WScript.CreateObject("SGFileSys.Enumerator")
-
- en.Recurse = true
- en.RootPath = sProjectFolder
- en.NameMask = "*.*"
- en.ExcludedFolders = "debug:release:"
- en.ExcludedExt = "scc:mdb:ncb:aps:plg:opt:mdp:bak:tmp:obj:o:exe:dll:" & _
- "lib:ocx:out:ex~:res:sbr:tlh:tli:trg:pdb:ilk:idb:pch:" & _
- "zip:log:ps:wc:vbw:oca:exp"
-
- ' Create shell objects
- Dim FS, WSH
- Set WSH = WScript.CreateObject("WScript.Shell")
- Set FS = CreateObject("Scripting.FileSystemObject")
-
- On Error Resume Next
-
- ' Prepare parameters
- sRootFolder = Replace(sRootFolder, "/", "\")
- sProjectFolder = Replace(sProjectFolder, "/", "\")
-
-
- ' Define destination drive and file
- Dim strDestDrive
- strDestDrive = GetRemovableDrive(FS)
- if strDestDrive = "" then
- msgbox "Unable to find removable drive"
- WScript.Quit
- end if
-
- ' Delete old compressed file
- if FS.FileExists(sZipFile + ".zip") then _
- FS.DeleteFile sZipFile + ".zip", True
-
- ' Create output file
- Dim strOutFile, outFile
- strOutFile = "FileList.txt"
- Set outFile = FS.CreateTextFile(strOutFile, True)
-
- ' Collect files to backup
- CollectFileNames en, sRootFolder, outFile
- Set outFile = Nothing
-
- ' Get WinZIP executable path
- Dim strWinZipFile
- strWinZipFile = WSH.RegRead("HKCR\WinZip\shell\open\command\")
- If (Trim(strWinZipFile) = "") Then
- MsgBox "Unable to find WinZIP.EXE file"
- WScript.Quit
- End If
- strWinZipFile = """" & Left(strWinzipFile, InStrRev(strWinzipFile, " ")-1) & """"
-
- ' Create command line and compress files
- Dim strParameters, strCmdLine, rc
- strParameters = "-a -r -p -ex " & sZipFile & ".zip @" & strOutFile
- strCmdLine = strWinZipFile & " " & strParameters
- rc = WSH.Run(strCmdLine, 9, True)
- If Err.Number <> 0 Then ReportError(True)
-
- ' Delete existing backups on the removable drive
- FS.DeleteFile strDestDrive & sZipFile & "*.zip", True
- If Err.Number<>0 And Err.Number<>53 then ReportError(True)
-
- ' Copy zipped file to the removable drive
- Err.Clear
- FS.CopyFile sZipFile & ".zip", strDestDrive & sZipFile & ".zip"
- If Err.Number <> 0 Then ReportError(True)
-
- WScript.Quit
-
-
-
- '----------------------------------------------------------------------------------
- ' CollectFileNames() subroutine walks folder tree and writes file paths
- ' to the specified text stream.
- '
- ' In:
- ' enum - SGFileSys.Enumerator object
- ' outRoot - string that will be removed from the start of the file path
- ' out - TextStream object that will contain collected file names
- '
- ' Out:
- ' File with list of files
- '----------------------------------------------------------------------------------
- Sub CollectFileNames(en, outRoot, out)
-
- Dim nPrefixLen, strPath, item
- outRoot = LCase(outRoot)
- nPrefixLen = Len(outRoot)
-
- for each item in en.items
- ' Do not emit directories into the result file
- if (item.Attributes And sgfDirectory) <> sgfDirectory then
- ' Remove root path from the current item path
- strPath = LCase(item.Path)
- if (nPrefixLen > 0) And (InStr(strPath, outRoot) = 1) then _
- strPath = Mid(strPath, nPrefixLen+1)
-
- ' Write file specification line
- out.WriteLine strPath
- end if
- next
- end sub
-
- '----------------------------------------------------------------------------------
- ' ReportError
- '----------------------------------------------------------------------------------
- Sub ReportError(bQuit)
- If Err.Number<>0 then
- MsgBox Err.Description + " (" + Err.Number + ")"
- if bQuit Then WScript.Quit
- End If
- End Sub
-
- '----------------------------------------------------------------------------------
- ' Find first removable drive
- '----------------------------------------------------------------------------------
- function GetRemovableDrive(fs)
- Dim drive
- for each drive in fs.Drives
- if drive.DriveType = 1 And drive.Driveletter <> "A" And drive.Driveletter <> "B" then
- GetRemovableDrive = drive.DriveLetter + ":\"
- exit function
- end if
- next
-
- ' Default is floppy A:
- GetRemovableDrive = "A:\"
- end function
-