我正在尝试获取特定文件夹中的目录列表,这些目录是在特定时间内创建的(例如,在第11小时期间创建的所有文件)。以下是我的代码:
import time
import os
def get_information(directory):
file_dict={}
for i in os.listdir(directory):
a=os.stat(os.path.join(directory,i))
b=time.gmtime(a.st_ctime)
newTime=b.tm_hour
if(file_dict.has_key(newTime)):
file_dict[newTime].append(i)
else:
file_dict[newTime]=[]
file_dict[newTime].append(i)
return file_dict
虽然我能够看到在第11个小时内创建了文件,但上面的代码无法提取它。
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181071677
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181071621
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181071661
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181071625
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181071673
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181055504
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181055500
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181055508
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181055512
drwxrwxr-x 2 oamops oamgroup 512 Aug 21 11:23 69-2181055516
另外需要注意的是,从0小时到第5小时有数据,然后数据从第18小时开始。
答案 0 :(得分:0)
尝试创建过滤功能:
<?php
include("connect.php");
$result = mysql_query("select * from rtable r inner join table_status as ts on ts.status_id=r.status_id where ts.status!='Booked' order by r.table_id desc")or die(mysql_error());
echo "<option disabled='disabled'>Select Table</option>";
while ($row=mysql_fetch_array($result))
{
echo "<option value=".$row['table_id'].">".$row['table_name']."</option>";
}
?>
然后只过滤你的目录:
import os, datetime
def check_time(path):
t = datetime.datetime.fromtimestamp(os.path.getmtime(path))
return t.hour == 11