网站首页 > 技术文章 正文
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-05-23 如何在Python中保存文件?如何读取文件?示例代码
- 2025-05-23 python读取Excel表格
- 2025-05-23 OpenCV-Python教程:从视频文件、相机获取图像、写视频文件
- 2025-05-23 Dify Sandbox实现文件路径获取与Excel数据处理
- 2025-05-23 python中文件读写操作最佳实践——使用 os.path 进行路径操作
- 2025-05-23 Python 开发工程师必会的 5 个文件操作库
- 2025-05-23 开眼界!Python遍历文件可以这样做
- 2025-05-23 白帽黑客如何通过dirsearch脚本工具扫描和收集网站敏感文件
- 2025-05-23 失业程序员复习python笔记——excel读写处理
- 2025-05-23 python怎么读取excel文件
- 05-25Python 3.14 t-string 要来了,它与 f-string 有何不同?
- 05-25Python基础元素语法总结
- 05-25Python中的变量是什么东西?
- 05-25新手常见的python报错及解决方案
- 05-2511-Python变量
- 05-2510个每个人都是需要知道Python问题
- 05-25Python编程:轻松掌握函数定义、类型及其参数传递方式
- 05-25Python基础语法
- 257℃Python短文,Python中的嵌套条件语句(六)
- 257℃python笔记:for循环嵌套。end=""的作用,图形打印
- 256℃PythonNet:实现Python与.Net代码相互调用!
- 251℃Python操作Sqlserver数据库(多库同时异步执行:增删改查)
- 251℃Python实现字符串小写转大写并写入文件
- 106℃原来2025是完美的平方年,一起探索六种平方的算吧
- 90℃Python 和 JavaScript 终于联姻了!PythonMonkey 要火?
- 81℃Ollama v0.4.5-v0.4.7 更新集合:Ollama Python 库改进、新模型支持
- 最近发表
- 标签列表
-
- python中类 (31)
- python 迭代 (34)
- python 小写 (35)
- python怎么输出 (33)
- python 日志 (35)
- python语音 (31)
- python 工程师 (34)
- python3 安装 (31)
- python音乐 (31)
- 安卓 python (32)
- python 小游戏 (32)
- python 安卓 (31)
- python聚类 (34)
- python向量 (31)
- python大全 (31)
- python次方 (33)
- python桌面 (32)
- python总结 (34)
- python浏览器 (32)
- python 请求 (32)
- python 前端 (32)
- python验证码 (33)
- python 题目 (32)
- python 文件写 (33)
- python中的用法 (32)