import os
while True:
content=input('请输入目录:') # file04
if os.path.exists(content):
'''表示路径存在'''
os.chdir(content) # 切换到输入的目录 切换到了file04目录
all_file_lst=os.listdir(os.getcwd())
# 获取目录列表形式 将file03目录下的文件或者文件夹以列表形式打印
print(all_file_lst) # ['c.txt', 'demon01.py', 'file05', '__init__.py']
file_lst=[] # 保存所有文件
dir_lst=[] # 保存所有文件夹
for file in all_file_lst:
if os.path.isfile(file): # 判断当前目录下面的内容是否为文件
'''文件'''
file_lst.append(file)
else:
'''文件夹'''
dir_lst.append(file)
# 打印所有的文件和文件夹
print('文件{}:'.format(file_lst))
print('文件夹{}'.format(dir_lst))
ret=input('请选择操作:添加前缀(A) 删除前缀(D) 添加文件(c) 删除文件(del) 修改文件名称(R)')
python批量加前缀
最新推荐文章于 2023-06-20 02:21:41 发布