当我运行我的函数时,它显示元组为空,即使它应该在目录中找到一些东西。
第一个函数"check_files('\SERVER1\C$\ directory \','*.pdf',‘TEST0’)“返回TRUE,因为目录中有一个文件。
对于以下函数,即使目录中有文件,它也会返回FALSE。执行一个print语句"Output“,结果显示

这使我认为它找不到目录,并将整个事情抛到一边。
怎么回事?
import os
import glob
def check_files(mydir, myext, name):
check = mydir + myext
print(str(check))
Output = glob.glob(check)
if Output == []: #FALSE
print (str(name) + 'All Operational.')
else: #TRUE
print (str(name) + 'I see some files here, please check the process.')
check_files('\\\SERVER1\\C$\\DIRECTORY\\', '*.pdf', 'Test 0')
check_files('\\\10.2.2.1\\Directory\\', '*.pdf', 'Test 1: ')
check_files('\\\10.3.2.1\\Directory\\', '*.pdf', 'Test 2: ')
check_files('\\\10.4.2.1\\Directory\\', '*.pdf', 'Test 3: ')发布于 2018-07-31 02:27:04
您需要转义所有的\字符。尝试运行print('\1')以了解原因。
check_files('\\\\10.2.2.1\\Directory\\', '*.pdf', 'Test 1: ')等。
https://stackoverflow.com/questions/51600103
复制相似问题