遍历目录

import os

savecwd = os.getcwd();

print "savecwd = ",savecwd


def list_dir(root,filefind ,folderfind ):
    if(os.path.isdir(root)):
        if folderfind :
            folderfind(root)
    elif os.path.isfile(root):
        if filefind:
            filefind(root);
        return;
    else:
        return;

    dir_lists = os.listdir(root)

    for dir in dir_lists:
        fullname = root + "/" + dir
        list_dir(fullname,filefind,folderfind)



你可能感兴趣的:(python)