Demo entry 6783511

py

   

Submitted by anonymous on Feb 15, 2019 at 02:58
Language: Python. Code size: 558 Bytes.

import os
import os.path
rootdir = "/Users/mei/Documents/Study/DNA/"                                   # 指明被遍历的文件夹

for parent,dirnames,filenames in os.walk(rootdir):    #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
	for dirname in dirnames:                       #输出文件夹信息
		print("parent is: " + parent)
		print("dirname is: " + dirname)
	
	for filename in filenames:                        #输出文件信息
		print("parent is: " + parent)
		print("filename is: " + filename)
		print("the full name of the file is: " + os.path.join(parent,filename)) #输出文件路径信息

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).