IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Python + Linux:判断是否是目录

    Adamhuan发表于 2017-05-12 02:39:01
    love 0

    代码:

    [root@oracle-cluster-3 python]# python -V
    Python 2.7.5
    [root@oracle-cluster-3 python]# 
    [root@oracle-cluster-3 python]# pwd
    /script/python
    [root@oracle-cluster-3 python]# 
    [root@oracle-cluster-3 python]# ls -ltr
    total 4
    -rw-r--r-- 1 root root 124 May 12 10:33 isDirectory.py
    [root@oracle-cluster-3 python]# 
    [root@oracle-cluster-3 python]# cat isDirectory.py 
    import os
    
    if os.path.isdir("/script"):
       print "dir /script is direcotry."
    else:
       print "dir /script is not direcotry."
    [root@oracle-cluster-3 python]# 
    [root@oracle-cluster-3 python]# python isDirectory.py 
    dir /script is direcotry.
    [root@oracle-cluster-3 python]#

    ————————————
    Done。



沪ICP备19023445号-2号
友情链接