如何使用 python 将数据从一个来源移动到另一个来源?
how to move data from one source to another source with python?
我想知道一个文件夹中的文件如何移动到另一个文件夹。在这里,python 脚本检测到文件已插入并且应该移动到另一个文件夹。
我们如何使流程自动化?
我尝试使用简单的 python 代码:
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')
是否使用多处理、队列或信号来执行此自动化过程?等..
您可以尝试使用 watchdog,
看看documentation 看看如何使用它
您可以在睡眠时使用 While True 来检查文件:
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
我想知道一个文件夹中的文件如何移动到另一个文件夹。在这里,python 脚本检测到文件已插入并且应该移动到另一个文件夹。
我们如何使流程自动化?
我尝试使用简单的 python 代码:
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')
是否使用多处理、队列或信号来执行此自动化过程?等..
您可以尝试使用 watchdog, 看看documentation 看看如何使用它
您可以在睡眠时使用 While True 来检查文件:
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