os.walk|图片数据集
该函数的功能:遍历指定文件夹下的所有【路径】【文件夹】【文件名】
''' os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]]) 参数: top -- 是你所要遍历的目录的地址, 返回的是一个三元组(root,dirs,files)。 root 所指的是当前正在遍历的这个文件夹的本身的地址 dirs 是一个 list ,内容是该文件夹中所有的目录的名字(不包括子目录) files 同样是 list , 内容是该文件夹中所有的文件(不包括子目录) topdown --可选,为 True,则优先遍历 top 目录,否则优先遍历 top 的子目录(默认为开启)。如果 topdown 参数为 True,walk 会遍历top文件夹,与top 文件夹中每一个子目录。 onerror -- 可选,需要一个 callable 对象,当 walk 需要异常时,会调用。 followlinks -- 可选,如果为 True,则会遍历目录下的快捷方式(linux 下是软连接 symbolic link )实际所指的目录(默认关闭),如果为 False,则优先遍历 top 的子目录。 '''
#查看root的所有值【root代表当前遍历文件夹的路径】 for root,dirs,files in os.walk(".",topdown=True): print(os.getcwd()) print(root) ''' 说明:topdown = True 从最上层开始遍历 得到当前文件夹下的所有文件夹 返回结果: D:pythonTensorFlow1_data_input_create4.3 ##1.当前工作目录一直没有改变(脚本所在目录) . ##遍历顶层文件夹【'.'代表当前工作目录【一层】】 D:pythonTensorFlow1_data_input_create4.3 ##1.当前工作目录一直没有改变(脚本所在目录) .mnist_digits_images ##遍历到子文件【二层】 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images ##遍历到子文件夹【三层】,【三层】有10个文件夹,一次遍历 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images1 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images2 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images3 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images4 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images5 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images6 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images7 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images8 D:pythonTensorFlow1_data_input_create4.3 .mnist_digits_images9 '''