python - if语句和日期时间模块python
问题描述
我在一个文件夹中有两个测试文件和这段代码
def check(source):
old_date = (datetime.datetime.now()) - (datetime.timedelta(days = 10))
source_files=os.listdir(source)
for file_name in source_files:
if (datetime.datetime.strptime(time.ctime(os.path.getctime(source+file_name)), "%a %b %d %H:%M:%S %Y")) > old_date:
print (str(datetime.datetime.strptime(time.ctime(os.path.getmtime(source+file_name)), "%a %b %d %H:%M:%S %Y") > old_date)+" copy")
else:
print ("do not copy")
check("C:\Python\OldFilesCopier\Source\\")
输出是
False copy
True copy
因此,一个文件应该应用 IF 语句,而第二个文件应该应用 ELSE 语句,但在这两种情况下,我都通过了 IF。找不到原因。
解决方案
推荐阅读
- python - 在 celery 任务中使用 django 模型
- php - 如何在sql中链接这两个表
- bash - 在bash中将空格分隔的字符串转换为逗号分隔
- c# - Entity Framework Core:自引用 FK 列值被替换为 `NULL`
- java - tableview javafx中字符串和属性字符串的区别
- jasmine-node - Claudia.js 茉莉花发布/放置正文密钥
- python - Folium 地图无法在 github 上的笔记本中呈现
- html - 基本 CSS:背景图像未加载
- php - 无法使用 Kartik 的 FileInput 小部件在 Yii2 框架中上传大于 97.66 KB 的文件
- mysql - 使用“不正确的参数”查询 MySQL 数据库以引发错误时,NodeJS 服务器崩溃