Jump to content

Bart74

Members
  • Posts

    1
  • Joined

  • Last visited

Bart74's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Thanks for this excellent script. I have modified it to my own needs. I wanted to sync ppt files to a working directory, also the ones that do not exist in the source should be deleted. Also it should not copy any ppt file that is opened for edit. Func Sync($from, $to, $ext, $withdelete) ; A modification from: ; http://www.autoitscript.com/forum/index.php?showtopic=29715 ; Building the logical source directory Local $returnVal = False Local $FilesFrom = FileFindFirstFile($from & "*." & $ext) While 1 Local $file = FileFindNextFile($FilesFrom) If @error Then ExitLoop ; Building the full path to source and destination file (or directory) Local $filename = FileGetLongName($from & $file) Local $tofilename = FileGetLongName($to & $file) ; Getting the mod. time of source and dest file... Local $fromtime = FileGetTime($filename, 0, 1) Local $totime = FileGetTime($tofilename, 0, 1) ; In case the destination file does not exists, $fromtime is always greater than $totime If $fromtime > $totime and not(FileLocked ($filename)) Then FileCopy($filename, $tofilename, 9) $returnVal = True EndIf WEnd ; Proper close of the file list FileClose($FilesFrom) ; If True, we should delete the files in the destination dir that do not exist in the source anymore If $withdelete Then Local $FilesTo = FileFindFirstFile($from & "*." & $ext) While 1 $file = FileFindFirstFile($FilesTo) If @error Then ExitLoop ; Building the full path to source and destination file (or directory) Local $filename = FileGetLongName($from & $file) Local $tofilename = FileGetLongName($to & $file) ;if the file in the from-dir does not exist, we should delete it in the dest-dir if not(FileExists ($fileName)) then FileDelete($tofileName) $returnVal = True EndIf WEnd FileClose($FilesTo) EndIf ; Return whether some copy/delete action took place return $returnVal EndFunc Func FileLocked ($fileName) ; Checks if a file is locked local $hFile = fileopen($fileName,1) Return $hFile <> -1 fileclose ($hFile) EndFunc
×
×
  • Create New...