TTyb

Python获取文件夹的名字

    dir = "../data/20170308/221.176.64.146/"
    # root 文件夹下的所有文件夹(包括子文件夹)的路径名字../data/20170308/221.176.64.146\1
    # dirs 返回文件夹下面所有文件(包括子文件夹)的文件夹名字数组[\'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\']
    # files 返回文件夹线面所有文件(包括子文件夹)的文件名字数组[\'newdata.json\', \'transformtxt.json\']
    for root, dirs, files in os.walk(dir):
        # print(root)
        # print(files)
        print(dirs)
        # for file in files:
        #     print(os.path.join(root, file))
# 获取当前目录下所有的文件夹名字
def getfilename(filename):
    for root, dirs, files in os.walk(filename):
        array = dirs
        if array:
            return array

分类:

技术点:

相关文章: