在函数再加一个参数 判断文件名称是否包含散航
时间: 2024-03-24 14:41:59 浏览: 16
好的,我可以帮你修改一下函数,增加一个参数用来判断文件名是否包含散航。下面是修改后的代码:
```python
import os
import time
def is_latest_file(file_path, has_sanhang=False):
# 判断文件名是否包含散航
if has_sanhang and "散航" not in file_path:
return False
# 获取文件的修改时间
mtime = os.path.getmtime(file_path)
# 将修改时间转换为本地时间
mtime_local = time.localtime(mtime)
# 获取当前时间
current_time = time.localtime()
# 比较文件的修改时间和当前时间
if mtime_local >= current_time:
return True
else:
return False
```
这个函数接受两个参数,第一个参数是文件路径,第二个参数是一个布尔值,表示是否需要判断文件名是否包含散航。如果 `has_sanhang` 参数为 `True`,则会判断文件名是否包含散航;如果文件名包含散航,则会根据文件的修改时间和当前时间来判断文件是否是最新的。如果文件名不包含散航,则直接返回 `False`。