网站首页 > 基础教程 正文
import os
import tkinter.filedialog
#递归获取指定目录下所有文件名
def get_all_file(path, list_name):
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
get_all_file(file_path, list_name)
else:
list_name.append(file_path)
#
if __name__ == '__main__':
#取当前目录
curDir = os.getcwd()
print('目录:', curDir)
# 打开文件对话框,选择目录
selDir = tkinter.filedialog.askdirectory()
print('选择目录:', selDir)
# 存储文件列表
file_list = []
#传入存储的list
get_all_file(selDir, file_list)
print(file_list)
猜你喜欢
- 2025-03-17 161.Python——读取中文路径图像文件
- 2025-03-17 零基础学Python的宝藏路径,结合教育场景,高效掌握编程不是梦!
- 2025-03-17 Python os.path模块使用指南:轻松处理文件路径
- 2025-03-17 Python处理文件系统路径,pathlib库使用
- 2025-03-17 VS code 中python 虚拟环境、目录组织和项目迁移
- 2025-03-17 Python入门系列2-添加Python安装路径到环境变量
- 2025-03-17 小问题大隐患:如何正确设置 Python 项目的入口文件?
- 2025-03-17 一文搞懂Python中的import与目录层级
- 2025-03-17 python中如何利用递归原理找出文件夹中的全部文件
- 2025-03-17 python 目录结构的规划,应该先建立好
- 最近发表
- 标签列表
-
- jsp (69)
- pythonlist (60)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (68)
- pythonifelse (59)
- deletesql (62)
- c++模板 (62)
- c#event (59)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- console.table (62)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)