创建某些文件类型的文件名列表,如果文件夹不包含文件类型,则打印此语句
Create list of files names of certain file types, if folder does not contain file type, print this statement
我正在根据文件夹中特定类型的文件创建文件名列表:
items = os.listdir(r'E:/folder/test')
print('checking directory...')
print('your files are: ')
print()
filenames = []
for names in items:
if names.endswith(".shp"):
filenames.append(names)
print(filenames)
print()
else:
print("there are no files ending with .shp in your folder")
如果文件夹中没有文件是 .shp 文件,我希望 if/else 有条件地打印一条说明这一点的语句。我的代码目前正在执行这两项操作,有什么解决方案吗?谢谢!
这是正确的代码:
items = os.listdir(r'E:/folder/test')
print('checking directory...')
print('your files are: ')
print()
filenames = []
for names in items:
if names.endswith(".shp"):
filenames.append(names)
print(filenames)
if not filenames:
print("there are no files ending with .shp in your folder")
我正在根据文件夹中特定类型的文件创建文件名列表:
items = os.listdir(r'E:/folder/test')
print('checking directory...')
print('your files are: ')
print()
filenames = []
for names in items:
if names.endswith(".shp"):
filenames.append(names)
print(filenames)
print()
else:
print("there are no files ending with .shp in your folder")
如果文件夹中没有文件是 .shp 文件,我希望 if/else 有条件地打印一条说明这一点的语句。我的代码目前正在执行这两项操作,有什么解决方案吗?谢谢!
这是正确的代码:
items = os.listdir(r'E:/folder/test')
print('checking directory...')
print('your files are: ')
print()
filenames = []
for names in items:
if names.endswith(".shp"):
filenames.append(names)
print(filenames)
if not filenames:
print("there are no files ending with .shp in your folder")