This commit is contained in:
guanjihuan 2024-02-28 09:41:05 +08:00
parent ca1ac5d96a
commit 3143694c7a
3 changed files with 9 additions and 25 deletions

View File

@ -1,7 +1,7 @@
[metadata] [metadata]
# replace with your username: # replace with your username:
name = guan name = guan
version = 0.1.85 version = 0.1.86
author = guanjihuan author = guanjihuan
author_email = guanjihuan@163.com author_email = guanjihuan@163.com
description = An open source python package description = An open source python package

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: guan Name: guan
Version: 0.1.85 Version: 0.1.86
Summary: An open source python package Summary: An open source python package
Home-page: https://py.guanjihuan.com Home-page: https://py.guanjihuan.com
Author: guanjihuan Author: guanjihuan

View File

@ -70,42 +70,26 @@ def read_text_file(file_path='./a.txt', make_file=None):
return content return content
# 获取目录中的所有文件名 # 获取目录中的所有文件名
def get_all_filenames_in_directory(directory='./', file_format=None, show_root_path=None): def get_all_filenames_in_directory(directory='./', file_format=None, show_root_path=0, sort=1, include_subdirectory=1):
import os import os
file_list = [] file_list = []
for root, dirs, files in os.walk(directory): for root, dirs, files in os.walk(directory):
for i0 in range(len(files)): for i0 in range(len(files)):
if file_format == None: if file_format == None:
if show_root_path == None: if show_root_path == 0:
file_list.append(files[i0]) file_list.append(files[i0])
else: else:
file_list.append(root+'/'+files[i0]) file_list.append(root+'/'+files[i0])
else: else:
if file_format in files[i0]: if file_format in files[i0]:
if show_root_path == None: if show_root_path == 0:
file_list.append(files[i0]) file_list.append(files[i0])
else: else:
file_list.append(root+'/'+files[i0]) file_list.append(root+'/'+files[i0])
return file_list if include_subdirectory != 1:
break
# 获取目录中的所有文件名(不包括子目录) if sort == 1:
def get_all_filenames_in_directory_without_subdirectory(directory='./', file_format=None, show_root_path=None): sorted(file_list)
import os
file_list = []
for root, dirs, files in os.walk(directory):
for i0 in range(len(files)):
if file_format == None:
if show_root_path == None:
file_list.append(files[i0])
else:
file_list.append(root+'/'+files[i0])
else:
if file_format in files[i0]:
if show_root_path == None:
file_list.append(files[i0])
else:
file_list.append(root+'/'+files[i0])
break
return file_list return file_list
# 获取文件夹中某种文本类型的文件以及读取所有内容 # 获取文件夹中某种文本类型的文件以及读取所有内容