0.1.85
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| [metadata] | [metadata] | ||||||
| # replace with your username: | # replace with your username: | ||||||
| name = guan | name = guan | ||||||
| version = 0.1.84 | version = 0.1.85 | ||||||
| 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 | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| Metadata-Version: 2.1 | Metadata-Version: 2.1 | ||||||
| Name: guan | Name: guan | ||||||
| Version: 0.1.84 | Version: 0.1.85 | ||||||
| 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 | ||||||
|   | |||||||
| @@ -56,12 +56,13 @@ def open_file(filename='a', file_format='.txt', mode='add'): | |||||||
|         f = open(filename+file_format, 'w', encoding='UTF-8') |         f = open(filename+file_format, 'w', encoding='UTF-8') | ||||||
|     return f |     return f | ||||||
|  |  | ||||||
| # 读取文本文件内容,如果不存在,则新建空文件,并返回空字符串 | # 读取文本文件内容。如果文件不存在,返回空字符串 | ||||||
| def read_text_file(file_path='./a.txt'): | def read_text_file(file_path='./a.txt', make_file=None): | ||||||
|     import os |     import os | ||||||
|     if not os.path.exists(file_path): |     if not os.path.exists(file_path): | ||||||
|         with open(file_path, 'w') as f: |         if make_file != None: | ||||||
|             pass |             with open(file_path, 'w') as f: | ||||||
|  |                 pass | ||||||
|         return '' |         return '' | ||||||
|     else: |     else: | ||||||
|         with open(file_path, 'r') as f: |         with open(file_path, 'r') as f: | ||||||
| @@ -69,29 +70,41 @@ def read_text_file(file_path='./a.txt'): | |||||||
|         return content |         return content | ||||||
|  |  | ||||||
| # 获取目录中的所有文件名 | # 获取目录中的所有文件名 | ||||||
| def get_all_filenames_in_directory(directory='./', file_format=None): | def get_all_filenames_in_directory(directory='./', file_format=None, show_root_path=None): | ||||||
|     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: | ||||||
|                 file_list.append(files[i0]) |                 if show_root_path == None: | ||||||
|  |                     file_list.append(files[i0]) | ||||||
|  |                 else: | ||||||
|  |                     file_list.append(root+'/'+files[i0]) | ||||||
|             else: |             else: | ||||||
|                 if file_format in files[i0]: |                 if file_format in files[i0]: | ||||||
|                     file_list.append(files[i0]) |                     if show_root_path == None: | ||||||
|  |                         file_list.append(files[i0]) | ||||||
|  |                     else: | ||||||
|  |                         file_list.append(root+'/'+files[i0]) | ||||||
|     return file_list |     return file_list | ||||||
|  |  | ||||||
| # 获取目录中的所有文件名(不包括子目录) | # 获取目录中的所有文件名(不包括子目录) | ||||||
| def get_all_filenames_in_directory_without_subdirectory(directory='./', file_format=None): | def get_all_filenames_in_directory_without_subdirectory(directory='./', file_format=None, show_root_path=None): | ||||||
|     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: | ||||||
|                 file_list.append(files[i0]) |                 if show_root_path == None: | ||||||
|  |                     file_list.append(files[i0]) | ||||||
|  |                 else: | ||||||
|  |                     file_list.append(root+'/'+files[i0]) | ||||||
|             else: |             else: | ||||||
|                 if file_format in files[i0]: |                 if file_format in files[i0]: | ||||||
|                     file_list.append(files[i0]) |                     if show_root_path == None: | ||||||
|  |                         file_list.append(files[i0]) | ||||||
|  |                     else: | ||||||
|  |                         file_list.append(root+'/'+files[i0]) | ||||||
|         break |         break | ||||||
|     return file_list |     return file_list | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user