Jump to content
Sign in to follow this  
myspacee

Fakecopy

Recommended Posts

myspacee

Hello,

for Production i must monitor and align 2 intranet folders, and do some operations when find changes.

Normally use Xcopy with /D option, crete txt list of copied files, and do things.

This time i can't use this method because file are HUGE.

So i think to create a script that take some informations from source file, and create a fake file on destination.

Create this quick and dirty AI script:

local $PATH_source = "D:\xxx\01-original\"
local $PATH_destination = "D:\xxx\02-copy\"
Local $search = FileFindFirstFile("D:\xxx\01-original\c_*.tif")   ; my files used first letter to differentiate


While 1
    Local $file = FileFindNextFile($search)
    If @error Then ExitLoop

   ;resetting flag 
   $f_something_change = 0
   
   ;find all SOURCE file info needed
   Local $source_t_modified = FileGetTime($PATH_source & $file, 0, 1)
   Local $source_t_created = FileGetTime($PATH_source & $file, 1, 1)
   Local $source_t_accesses = FileGetTime($PATH_source & $file, 2, 1)
   Local $source_f_attrib = FileGetAttrib($PATH_source & $file)


    ;if file not exist in DEST create FAKE one
    if NOT FileExists($PATH_destination & $file) then 
      $file_destination = FileOpen($PATH_destination & $file, 10) 
      FileClose($file_destination)
      
      FileSetAttrib($PATH_destination & $file, $source_f_attrib, 0)
      FileSetTime($PATH_destination & $file, $source_t_modified, 0, 0)
      FileSetTime($PATH_destination & $file, $source_t_created, 1, 0)
      FileSetTime($PATH_destination & $file, $source_t_accesses, 2, 0)

   Else ;IF file already exist...
      
      ;find all EXISTING file info needed
      $existing_t_modified = FileGetTime($PATH_destination & $file, 0, 1)
      $existing_t_created = FileGetTime($PATH_destination & $file, 1, 1)
      $existing_t_accesses = FileGetTime($PATH_destination & $file, 2, 1)
      $existing_f_attrib = FileGetAttrib($PATH_destination & $file)
      
      ;and compare with SOURCE file info
      IF $existing_t_modified <> $source_t_modified then $f_something_change = 1
      IF $existing_t_created <> $source_t_created then $f_something_change = 1
      IF $existing_t_accesses <> $source_t_accesses then $f_something_change = 1
      IF $existing_f_attrib <> $source_f_attrib then $f_something_change = 1
         
      ;if something change
      if $f_something_change = 1 Then ;overwrite destination with new FAKE file
         FileDelete($PATH_destination & $file)
         
         $file_destination = FileOpen($PATH_destination & $file, 10) 
         FileClose($file_destination)

         FileSetAttrib($PATH_destination & $file, $source_f_attrib, 0)
         FileSetTime($PATH_destination & $file, $source_t_modified, 0, 0)
         FileSetTime($PATH_destination & $file, $source_t_created, 1, 0)
         FileSetTime($PATH_destination & $file, $source_t_accesses, 2, 0)
      EndIf
      
      
   endif
         
    FileClose($file)    
    
WEnd

; Close the search handle
FileClose($search)

Can you suggest if approach it's right, and adjust my dirty script?

Thank you,

m.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×