Search code examples
pythonpython-3.xmultithreadingfilesystemspython-multiprocessing

how to move data from one source to another source with python?


I am trying to know how files are in one folder move to another folder. Here, python script sense that files got inserted and should move to another folder.

how can we automate the process?

I tried with simple python code:

import shutil
import os

source = '/directory&files/directory1/'
dest = '/directory&files/directory1/sample/'

files = os.listdir(source)

if len(files) == 10:
   for f in files:
    shutil.move(source+f, dest)   
else:
    print('Have no file exist or More files to be append')

Is any of doing this automate process using of multiprocessing, queue or signals? etc..


Solution

  • you can using While True with sleep, for checking files:

    import time
    while True:
        if len(files) == 10:
           for f in files:
            shutil.move(source+f, dest)   
        else:
            print('Have no file exist or More files to be append')
        time.sleep(5) #delay time in sec