逐行獲取一個(gè)文件的內(nèi)容
def get_content_list_form_file(infilename):
infile = open(infilename, "r")
inlines_list = infile.readlines()
infile.close()
cleaned_lines = [line.strip() for line in inlines_list]
return cleaned_lines
獲取文件夾下所有文件的路徑
def list_files_in_folder(input_dir):
file_path_list = []
for filename in os.listdir(input_dir):
filename_path = os.path.join(input_dir, filename)
if os.path.isfile(filename_path):
file_path_list.append(filename_path)
return file_path_list
創(chuàng)建新的文件夾
def mkdir(new_dir_name):
new_dir_path=os.path.abspath(new_dir_name)
if not os.path.exists(new_dir_path):
os.makedirs(new_dir_path)
print(f"Output path: {new_dir_path}")
else:
print('Directory already exists: {}'.format(new_dir_path))
exit()
return new_dir_path