0

I have a server location (source) where client provides number of files frequently all day long. My task is to copy them into another server location (destination) and move those copied files from source location to another sub directory in the source server. Like:

Before Copy:

Server A
/files
  --- /done
  --- File1.xml
  --- File2.xml
  --- File3.xml

Server B
/files

After Copy to Destination Server B and copied files moved to done folder of Source Server A:

Server B
/files
  --- File1.xml
  --- File2.xml
  --- File3.xml

Server A
/files 
  --- File4.xml
  --- /done
    --- File1.xml
    --- File2.xml
    --- File3.xml

I want to automate this process and I have looked through the windows robocopy to achieve this. But while copying the files I faced a problem whenever client provides a new file like File4.xml and isn't fully copied, it have a risk to copy them too. How can properly copy and moves the file as explained above? Both servers are running on windows.

Nafi Pantha
  • 169
  • 1
  • 3
  • 16

1 Answers1

0

From the 'A' directory you could run the following python script and the work would be done. You can define some time (see the commented section) so that files that were just added will be ignored

import os
import time
from shutil import copy
   for i in os.listdir():
       if i !='done' and #(time.time()-os.stat(i).st_ctime > define_some_time_limit_to_avoid_copying_recent_files):
           copy('source_path_A'+i, 'destination_path_B'+i)
           copy('source_path_A'+i, 'destination_path_A_done'+i)
           os.remove('source_path'+i)
IoaTzimas
  • 10,538
  • 2
  • 13
  • 30