我收到此错误
[Errno 22] Invalid argument: 'S:\\Job Data$\\Jobs\\14-00060006\\Completed Files\\14-00060006_data.txt'
和其他人试图打开文件。我认为这是因为 \14 和 \13 等,但我不确定。
这是代码:
def crawl(path, phrase=""):
found_files = 0
for root, dirs, files in os.walk(path):
for f in files:
if f.endswith(".txt"):
found_file = os.path.join(root, f)
if phrase != "":
try:
with open(found_file, mode='r') as text_file:
for line in text_file:
for part in line.split():
if phrase in part:
found_files += 1
print("\n\nFound one:")
print(found_file)
print(line)
except Exception as e:
print(e)
我试图在目录树中找到特定的单词,数千个目录都以年份为前缀,2014 年为 14,依此类推,无法更改,我怎样才能让 python 读取这些文件?