emmanuel Posted September 17, 2004 Share Posted September 17, 2004 (edited) expandcollapse popup#include-once ;=============================================================================== ; ; Description: Copy file and overwrite only if target is newer ; Syntax: __FileCopyNewer( $sSrc, $sTrgt, $iOpt ) ; Parameter(s): $sSrc - Path and filename to ; $sTrgt - Path and filename to ; $iOpt - Time attribute to be used, same as FileGetTime ; 0 = Modified ; 1 = Created ; 2 = Accessed ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; @error = -1; if the target file is newer than the source ; On Failure - Returns 0 and sets: ; @error = 1: Error finding file or retreiving it's time ; @error = 2: File copy failed ; Author(s): Emmanuel Pleshe <emmanuel.pleshe@gmail.com> ; Note(s): I don't know what this will do with wildcards. ; ;=============================================================================== #cs ;demo: $source = "C:\Documents and Settings\&eplesh\Desktop\leet.jpg" $target = "C:\test.jpg" $opt = 0 $testing = _FileCopyNewer($source, $target, $opt) $error = @error MsgBox(4096, 'debug:', '$testing:' & $testing);### Debug MSGBOX MsgBox(4096, 'debug:', '$error:' & $error);### Debug MSGBOX #ce Func _FileCopyNewer($sSrc, $sTrgt, $iOpt) $sSrcMod = FileGetTime($sSrc, $iOpt) $sTrgtMod = FileGetTime($sSrc, $iOpt) If $sSrcMod = 1 Then SetError(1) Return 0 EndIf ;my first thought was that if I added all the elements of each array, the older file would have a smaller number ;yeah, I'm short on caffeen. if ($sSrcMod[0] & $sSrcMod[1] & $sSrcMod[2] & $sSrcMod[3] & $sSrcMod[4] & $sSrcMod[5]) > _ ($sTrgtMod[0] & $sTrgtMod[1] & $sTrgtMod[2] & $sTrgtMod[3] & $sTrgtMod[4] & $sTrgtMod[5]) _ Or FileExists($sTrgt) = 0 Then $iCopyTest = FileCopy($sSrc, $sTrgt, 1) If $iCopyTest = 0 Then SetError(2) Return 0 Else Return 1 EndIf Else SetError(-1) Return 1 EndIf EndFunc ;==>_FileCopyNewer Edited September 17, 2004 by emmanuel "I'm not even supposed to be here today!" -Dante (Hicks) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now