# coding=utf-8
# @author:Damon Qu
# @contact:qufengw@126.com
# @date:2018/5/23
import os
'''
获取指定目录下所有文件名,并按格式写入指定文件
'''
def file_name(dir_path, target_file):
f = open(target_file, 'w')
count = 0
for file in os.listdir(dir_path):
if os.path.isfile(dir_path + '/' + file):
count += 1
f.write("'%s'\n" % file)
f.close()
print("write over, the count of files is: %d" % count)
dir_path = input("enter dir path: ")
target_file = input("enter target file name: ")
file_name(dir_path, target_file)
获取指定目录下所有文件名,并按格式写入指定文件
最新推荐文章于 2024-03-11 11:02:04 发布
本篇博客介绍了一个简单的Python脚本,该脚本能够批量读取指定目录下的所有文件名,并将这些文件名记录到另一个指定文件中。通过用户输入目标目录路径及输出文件名,脚本会自动完成文件名的读取与记录工作。
2248

被折叠的 条评论
为什么被折叠?



