[英]Python - Moving Outlook Mail from Inbox to Folder Based on Folder Name
[英]Entering folder based on name in python
在我的代碼中,我可以在目錄中搜索具有特定名稱的文件。 我該如何編輯代碼,以便它首先搜索名稱以單詞“ output”結尾的文件夾。 在下面的代碼中,當我嘗試添加注釋掉的行時,整個程序都拒絕運行。 我所缺少的任何幫助將不勝感激
def test():
file_paths = []
filenames = []
for root, dirs, files in os.walk('/Users/Bashe/Desktop/121210 p2/'):
for file in files:
#if re.match("output", file):
if re.match("Results",file):
file_paths.append(root)
filenames.append(file)
return file_paths, filenames
要搜索名稱以單詞“ output”結尾的文件夾中的文件:
for dirpath, dirs, files in os.walk(rootdir):
if not dirpath.endswith('output'):
continue # look in the next folder
# search files
for file in files: ...
如果您甚至不想訪問任何不以"output"
結尾的目錄:
if not rootdir.endswith('output'):
return # do not visit it at all
for dirpath, dirs, files in os.walk(rootdir):
assert dirpath.endswith('output')
dirs[:] = [d for d in dirs if d.endswith('output')] # edit inplace
# search files
for file in files: ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.