code
- import os
- def scanfile(path):
- filelist = os.listdir(path)
- allfile = []
- for filename in filelist:
- filepath = os.path.join(path,filename)
- if os.path.isdir(filepath):
- scanfile(filepath)
- print filepath
- allfile = scanfile('C:/studyPy')
- for path,d,filelist in os.walk("C:/studyPy"):
- for filename in filelist:
- os.path.join(path,filename)
-
import os # Import the OS module
arr = []
if not os.path.exists('testdir'): # Check to see if it exists
os.makedirs('testdir') # Create the directory
print ('1000')
else:
for path, d, filelist in os.walk("testdir"):
for filename in filelist:
print (os.path.join(path, filename))
def scanfile(path,arr):
filelist = os.listdir(path)
allfile = []
for filename in filelist:
filepath = os.path.join(path,filename)
if os.path.isdir(filepath):
scanfile(filepath)
# print (filepath)
arr.append(filepath)
allfile = scanfile('testdir',arr)
for file in arr:
print("current filepath is : %s"%(file))
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步