os.listdir(file)用于返回指定的文件夹包含的文件夹或者文件夹名的列表。
如下我在d盘中建立一个test文件,然后在test文件中新建三个文件夹mytest1,mytest2,mytest3。
然后在编译器中输入如下代码:
import os
file = "D:/test"
temp = os.listdir(file)
print(temp)
运行,结果在控制台中输出如下:
os.listdir(file)用于返回指定的文件夹包含的文件夹或者文件夹名的列表。
如下我在d盘中建立一个test文件,然后在test文件中新建三个文件夹mytest1,mytest2,mytest3。
然后在编译器中输入如下代码:
import os
file = "D:/test"
temp = os.listdir(file)
print(temp)
运行,结果在控制台中输出如下: