导出目录下文件名--python实例

实验环境 CentOS,将所有目录名称保存在特定目录的 pickname.txt 文档里。

#!/usr/bin/python
# name:pickname.py
# author:wubolu
# data:20110727

import os
dirname=raw_input("Enter dirname:\n")

if os.path.isdir(dirname):
    listname=os.listdir(dirname)
    r=open('pickname.txt','w')
    for i in listname:
        r.write(i+'\n')
    r.close()
else:
    print "Without this path or not a path, try agin.\n"

你可能感兴趣的:(python)