我的python脚本:
#!/usr/bin/python
import CameraID
import time
import os
image="/tmp/image/frame.png"
count = 1
while (count==1):
# make sure file file exists, else show an error
if ( not os.path.isfile(image)):
print("Error: %s file not found" %image)
else:
print("Sending file %s ..." % image)
print CameraID.run()
print os.remove("/tmp/image/frame.png")
是否有人知道如何允许使用不同的文件名一次发送一个文件。文件发送后,将立即删除。
答案 0 :(得分:0)
也许可以使用list来保存文件,例如:image = [“/ tmp / image / frame.png”,“”] 然后在图像中使用x:
答案 1 :(得分:0)
只需列出要传输的文件,然后遍历该列表即可逐个发送文件。
这是一个获取文件列表的简单函数:
def list_of_files(folder, extension):
'''
Return a list of file-paths for each file into a folder with the target extension.
'''
import glob
return glob.glob(str(folder + '*.' + extension))
在你的情况下,它将是:
files = list_of_files('/tmp/image/','png')
for image in files:
if ( not os.path.isfile(image)):
print("Error: %s file not found" %image)
else:
print("Sending file %s ..." % image)
print CameraID.run()
print os.remove(image)
没有功能定义:
import glob
files = glob.glob('/tmp/image/*.png')
for image in files:
if ( not os.path.isfile(image)):
print("Error: %s file not found" %image)
else:
print("Sending file %s ..." % image)
print CameraID.run()
print os.remove(image)