ETCopy a vbScript for copying files and foldersYou ever needed to copy files or sync a folder in the Logon script for Windows, when you have Active Directory and you are not allowed to use RoboCopy?Well, I did. I was asked to do everything in vbScript, because the logon script would only use vbScript. So I started to re-write RoboCopy and only use vbScript to do that. Ofcourse it started as a joke but, now it's getting pretty much a real program.
I would like to ask you programmers to have a look at my program and comment on it.
You can download ETCopy as a zip file from here. <----- You can use the source of ETCopy as an example for different waysto use the FileSystemObject in vbScript:
Do you know how to handle wildcard selection with a RegExp?
Example 1, Argument Handling.
i = 2
While i < WScript.Arguments.Count
arg = WScript.Arguments(i)
If Left(arg,1) = "/" Then
Example 2, Array Handling.
arrSourceFiles = Split(argSourceFiles,",")
Example 3, FileExists.
While objFSO.FileExists(strNewName) And intLogCopy < 1000
intLogCopy = intLogCopy + 1
strLogExt = "." & Right("000"&intLogCopy,3)
strNewName = strLogFile & strLogExt
Wend
Example 4, Recursively scan through subfolders.
Sub ScanFolders(oFolder, rFolder)
For each folder in oFolder.SubFolders
... actions ....
ScanFolders folder, strRelFolder & "\" & folder.Name
Next
End If
End Sub
Example 5, File attributes.
Function isAttribRSH(objectF)
isAttribRSH = False
If objectF.Attributes And 7 Then ' 7 = R (1) + H (2) + S (4)
isAttribRSH = True
End If
End Function
Example 6, Check Drive Size.
Function CheckDriveSize(oFile)
Dim DriveSpec
Dim drive
Dim SafeSize
CheckDriveSize = False
SafeSize = 10000000 ' more then 10MB must exist
DriveSpec = objFSO.GetDriveName(objFSO.GetAbsolutePathName(argTargetFolder))
Set drive = objFSO.GetDrive(DriveSpec)
If drive.AvailableSpace > oFile.Size + SafeSize Then
CheckDriveSize = True
End If
Set drive = Nothing
End Function
And many more ....... Latest Changes:
.LOG
20:19 12/Oct/07
Created version 1.6
Now ETCopy can be called from an other VBScript.
Example is in Sync_Now.vbs
16:59 3/5/2007
The DeleteFolder method does not distinguish between folders that have contents
and those that do not. The specified folder is deleted regardless of whether it has contents.
Also if the user is owner of the folder, the folder is deleted regardless of whether the folder is readonly.
11:09 3/5/2007
Version 1.5
Added option /Zero, if set exit code is always 0.
Completed the Exit return codes
Everytime an error is encountered and the program is not stopped,
the Exit code is increased by 1
If the program is aborted then the exit code is 1 even if option is set with /Z
22:07 3/1/2007
Changed the way the log is created
If /MIR is specified other options are ignored
/R /S /E and /PUR are implicit with /MIR
/MIR will not copy same files
DeleteFolder does not work as expected, ForceDelete has no effect.
Not solved, needs investigation.
Created MyFormatDate to be YYYYMMDD independant of regional settings
Abort program if targetfolder can not be created.
Completely revised the manual.
20:54 3/1/2007
included the /ReadOnly option, it works on Purge, Copy and Mirror
/ReadOnly is checking ReadOnly, Hidden and System Files
Changed Copy file options:
Default will not copy same files
/COPY will also copy same files
17:04 3/1/2007
Version 1.4
Included the show of file and folder attributes
Added Free Space for target drive in Log
01:01 3/1/2007
Included the /EmptyFolder option
Solved problem with deleting extra folder
22:38 2/28/2007
Version 1.3
Revised the error handling
19:57 2/27/2007
Version 1.2
Changed CheckDriveSize just before copying
Changed XD and XF Parameter slightly
Checked for \ at end of folder names except root (c:\)
Extra check for target folder
13:14 25/01/2007
Version 1.1
Created the Options XF and XD
Files and also wildcards are excluded from any operation.
14:13 23/01/2007
Added check on diskspace
Just before the copy diskspace is checked with use of 10 MB extra, space > file + 10MB
10:42 23/01/2007
Add Option /TEE argOptionLogEcho
This will display output to the console.
10:29 23/01/2007
Minor changes to help file and manual.
10:25 23/01/2007
Solved BUG with *. wildcard, partly. Checking 5 character extensions, if more, it's not an extension.
13:57 22/01/2007
Started version 1.0
files argument has been Array'ed
Now more arguments can be handled, the arguments should be separated by comma's
========================
Usage:
***************************************************************************************
ETCopy.vbs :: vbScript Copy :: Version 1.6
Created by :: Edmond ter Riet :: All rights reserved (2007)
***************************************************************************************
Usage:
cscript ETCopy.vbs Sourcefolder Destinationfolder [file] <options> <parameters>
Sourcefolder The folder to copy from (it must exist)
Destinationfolder The folder to copy to (complete path is created)
files The file(s) to copy, use wildcards, separate with comma or space
Options:
/COPy Copy all files, even same files
/MIRror Keep source and destination exactly the same
/PURge Purge all extra files and folders from destination
/XO Exclude older files
/R or /REA Overwrite and Delete Read-Only, Hidden and System files
/S or /SUB Copies subfolders excluding empty ones
/E or /EMP Copy also empty folders
If /MIR is specified other options are ignored
/R /S /E and /PUR are implicit with /MIR
/MIR will not copy same files
Parameters:
/L or /LIS Do not actually copy, just list
/LOG Switch on logging
/LOG+ Append to the logfile
/LOG# Rename the logfile first, limit = 999
/LOG:<file> Specify the logfile
/LOG+:<file> Specify the logfile to append
/LOG#:<file> Specify the logfile to rename
Report Parameters:
/NS or /NOS Report no filesizes
/ND or /NOD Report no filedates
/Z or /ZER Always exit with return code zero
Exclusions:
/XF: Exclude Files, can contain wildcards
/XD: Exclude Folders, can contain wildcards
File compare flags:
L(onely) Only in source
S(ame) Both date and size are the same
C(hanged) Date is the same and size is different
N(ewer) Sourcedate is newer then destination
O(lder) Sourcedate is older the destination
E(xtra) Only in destination
File execute flags:
C(opied) File has been copied
A(bort) File copy has been aborted (Diskspace)
P(urge) File/Folder has been purged
E(cluded) File/Folder has been excluded
R(eadOnly) File/Folder is Readonly or Hidden
File or Folder attributes:
R Read-only
H Hidden
S System
A Archive
C Compressed
By default read-only, hidden and system files are not copied
or deleted, unless /R, /Readonly or /MIR is specified
By default same files or not copied, unless /COP is specified
Any parameter with arguments should not contain spaces
If a parameter has arguments they should be separated with comma's
Parameters are similar to RoboCopy, but not equal
All unknown parameters are ignored
Arguments that do not start with a / are seen as file definitions
There are two ways in which ETcopy can be called.
1) Directly from the command line or from a shortcut.
The parameters for the command are stored in the arguments collection object.
2) ETCopy is included by another script. The program including ETCopy needs to
dim variable includeEtcopy and call function ETCOPY_FROM_SCRIPT
|