Update creat_necessary_file_or_delete_file_with_specific_name.py
This commit is contained in:
		| @@ -14,13 +14,20 @@ def main(): | |||||||
|     # guan.delete_file_with_specific_name(directory) |     # guan.delete_file_with_specific_name(directory) | ||||||
|  |  | ||||||
|  |  | ||||||
| def creat_necessary_file(directory, filename='readme', file_format='.md', content=''): | def creat_necessary_file(directory, filename='readme', file_format='.md', content='', overwrite=None): | ||||||
|     import os |     import os | ||||||
|     directory_with_file = [] |     directory_with_file = [] | ||||||
|  |     missed_directory = [] | ||||||
|     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 root not in directory_with_file: |             if root not in directory_with_file: | ||||||
|                 directory_with_file.append(root) |                 directory_with_file.append(root) | ||||||
|  |             if files[i0] == filename+file_format: | ||||||
|  |                 if root not in missed_directory: | ||||||
|  |                     missed_directory.append(root) | ||||||
|  |     if overwrite == None: | ||||||
|  |         for root in missed_directory: | ||||||
|  |             directory_with_file.remove(root) | ||||||
|     for root in directory_with_file: |     for root in directory_with_file: | ||||||
|         os.chdir(root) |         os.chdir(root) | ||||||
|         f = open(filename+file_format, 'w', encoding="utf-8") |         f = open(filename+file_format, 'w', encoding="utf-8") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user