1. 程式人生 > >python 獲取目錄下的檔案資訊

python 獲取目錄下的檔案資訊

獲取某個目錄下深度為1的目錄和檔案的大小和最近的修改時間:

for item in os.listdir(request_path):
	full_path = os.path.join(request_path,item)
	fsize = os.path.getsize(full_path)
	fmtime = timeStampToTime(os.path.getmtime(full_path))
	if os.path.isdir(full_path):
		file_list['dirs'].append({'name':item,'fsize':str(fsize)+'KB','fmtime':fmtime})
	else:
		file_list['files'].append({'name':item,'fsize':fsize,'fmtime':fmtime})