Larsongo的博客

但行心事,莫问前程

目录文件查看
#!/usr/bin/python
# -*- coding:gbk -*-

import os

allFileNum = 0
allDirNum = 0


def printpath(path):
    global allFileNum
    global allDirNum
    dirList = []
    fileList = []
    for df in path:
        print df
        if os.path.isdir(df):
            dirList.append(df.decode('gbk'))
        if os.path.isfile(df):
            fileList.append(df.decode('gbk'))
    for dl in dirList:
        allDirNum += 1
        print dl
    for fl in fileList:
        allFileNum += 1
        print fl
    print allDirNum, allFileNum


def recent_file():
    rec = []
    for i in os.listdir(os.getcwd()):
        if i.isdigit():
            rec.append(i)
    os.startfile(max(rec))


def walkpath(path):
    file = open(r'D:\file_list.txt','w')
    for parent, dirnames, filenames in os.walk(path):
        for dirname in dirnames:
            print "parent is:" + parent.decode('gbk')
            file.write(parent + '\n')
            print "dirname is" + dirname.decode('gbk')
            file.write(dirname + '\n')
        for filename in filenames:  # 输出文件信息
            print "parent is:" + parent.decode('gbk')
            file.write(parent + '\n')
            print "filename is:" + filename.decode('gbk')
            file.write(filename + '\n')
            print "the full name of the file is:" + os.path.join(parent.decode('gbk'), filename.decode('gbk'))
            file.write(os.path.join(parent, filename) + '\n')
    file.close()


if __name__ == '__main__':
    os.chdir(r"D:\Svn\yunwei\测试管理")
    nowpath = os.listdir(os.getcwd())
    printpath(nowpath)
    recent_file()
    walkpath(os.getcwd())


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lisheninasiainfo/article/details/53996049
个人分类: python
想对作者说点什么? 我来说一句

查看服务器端目录文件

piperzero piperzero

2008-11-19 12:39:00

阅读数:900

没有更多推荐了,返回首页

不良信息举报

目录文件查看

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭