以下代码列出了具有 gfs.t*... 模式的文件,我还需要检查所有文件的大小是否超过 1000 (int(os.path.getsize(file))>1000)。但我只得到有关列表最后一个文件下载的结果。代码有什么问题吗?提前致谢
#! /opt/python2.7/bin/python2.7
from datetime import datetime
import os
import urllib
import shutil
import multiprocessing
import time
import glob
today = datetime.now()
if today.hour < 14:
h = "00"
else:
h = "12"
folder = "/home/Gribs/GFS0.25-p/gfs." + today.strftime('%Y%m%d')+ h
if not os.path.exists(folder):
os.mkdir("/home/Gribs/GFS0.25-p/gfs." + today.strftime('%Y%m%d')+ h)
os.chdir(folder)
for file in glob.glob("gfs.t*"):
print (file)
if(int(os.path.getsize(file))>1000):
print (file + "downloaded right")
else:
print (file + "not downloaded right")
最佳答案
试试这个,if else block 应该在 for 循环内缩进。
for file in glob.glob("gfs.t*"):
print (file)
if(int(os.path.getsize(file))>1000):
print (file + "downloaded right")
else:
print (file + "not downloaded right")
关于python - 引用python中文件的下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43425158/