;; ;;=====================================================================================----- ;; ;;FUNCTION FolderMod() ;; ;;ACTION Determines if any changes were made to a folder structure ;; ;;AUTHOR Glenn Barnas ;; ;;VERSION 1.0 - 2009/04/09 ;; ;;HISTORY 1.0 - 2009/04/09 - Initial Release ;; ;;SYNTAX FolderMod(Root, Datestamp [, Options]) ;; ;;PARAMETERS Root - REQUIRED - String ;; - The path to the root of a folder structure. Returns true if any files ;; or folders below this path were modified since the supplied datestamp. ;; ;; DateStamp - REQUIRED - Date String ;; - the date to compare against. Must be a string in the format ;; YYYY/MM/DD HH:MM - seconds are ignored in this comparison. ;; ;; Options - OPTIONAL - Integer ;; - A cumulative value that controls the operation of FolderMod ;; 1 - Depth - Scan subfolders when set, otherwise only scan the named folder ;; 2 - Dirs - Limit the scan to folder timestamps to improve performance at ;; the risk of missing modified files. Suitable for tracking new and deleted ;; files. ;; ;;REMARKS Returns TRUE if any file object has a modified date newer than the ;; timestamp provided. Checking folder modification times can improve ;; performance, since creating or deleting a file will update the timestamp ;; of the folder it resides in. Note that modifying an existing file will not ;; modify a folder timestamp. The function temporarily modifies the date and ;; time formats to yyyy/mm/dd HH:mm:ss so that all comparisons are equal ;; regardless of international settings. ;; ;;RETURNS Int - 1 if a file object has been modified since Datestamp, 0 otherwise. ;; ;;DEPENDENCIES None ;; ;;TESTED WITH W2K, WXP, W2K3, Vista, W2K8 ;; ;;EXAMPLES None ; Function FolderMod($_Root, $_DateStamp, OPTIONAL $_Options) Dim $_Rv ; return value Dim $_Cmd ; Dir command to run Dim $_Last ; last update time Dim $_Files ; array of file objects Dim $_Sort ; external sort Flag Dim $_oExec ; WSH pointer Dim $_RTime[1] ; current Date/Time format in registry ; retrieve original date/time format strings $_RTime[0] = ReadValue('HKCU\Control Panel\International', 'sShortDate') $_RTime[1] = ReadValue('HKCU\Control Panel\International', 'sTimeFormat') ; write what we need $_Rv = WriteValue('HKCU\Control Panel\International', 'sShortDate', 'yyyy/MM/dd', 'REG_SZ') $_Rv = WriteValue('HKCU\Control Panel\International', 'sTimeFormat', 'HH:mm:ss', 'REG_SZ') $_DateStamp = Left($_DateStamp, 16) ; trim seconds if supplied $_Options = Val($_Options) ; force to numeric value $_Cmd = '%COMSPEC% /c dir "' + $_Root + '" /T:W' ; base command If $_Options & 1 $_Cmd = $_Cmd + ' /S' ; process subfolders EndIf If $_Options & 2 $_Cmd = $_Cmd + ' /A:D' ; directories only EndIf ; "/O-D" significantly improves the final sort performance by sorting results within folders. ; Find restricts results to lines containing a date. ; "Sort /Rev" sorts the data stream from newest to oldest. $_Cmd = $_Cmd + ' /O-D | Find "/" | Sort /Rev' ; sorted result $_oExec = CreateObject("WScript.Shell").Exec($_Cmd) ; run the command If VarType($_oExec) = 9 $_Files = Split($_oExec.StdOut.ReadAll, @CRLF) ; get array ; first record is the newest timestamp $_Last = Join(Split(Left($_Files[0], 17), ' '), ' ') Else Exit 10 EndIf $FolderMod = 0 ; default return value If $_Last > $_DateStamp $FolderMod = 1 ; IsModified return value EndIf ; restore the original format settings $_Rv = WriteValue('HKCU\Control Panel\International', 'sShortDate', $_RTime[0], 'REG_SZ') $_Rv = WriteValue('HKCU\Control Panel\International', 'sTimeFormat', $_RTime[1], 'REG_SZ') Exit 0 EndFunction