zoukankan      html  css  js  c++  java
  • 目录文件处理

    >>> import os
    >>> cwd = os.getcwd()
    >>> cwd
    '/home/dinsdale'
    
    cwd stands for “current working directory”. The result in this example is /home/dinsdale, which is the home directory of a user named dinsdale.
    A string like '/home/dinsdale' that identifies a file or directory is called a path.
    A simple filename, like memo.txt is also considered a path, but it is a relative path because it relates to the current directory. If the current directory is /home/dinsdale, the filename memo.txt would refer to /home/dinsdale/memo.txt.
    A path that begins with / does not depend on the current directory; it is called an absolute path. To find the absolute path to a file, you can use os.path.abspath:
    
    >>> os.path.abspath('memo.txt')
    '/home/dinsdale/memo.txt'
    os.path provides other functions for working with filenames and paths. For example, os.path.exists checks whether a file or directory exists:
    
    >>> os.path.exists('memo.txt')
    True
    If it exists, os.path.isdir checks whether it’s a directory:
    
    >>> os.path.isdir('memo.txt')
    False
    >>> os.path.isdir('/home/dinsdale')
    True
    Similarly, os.path.isfile checks whether it’s a file.
    os.listdir returns a list of the files (and other directories) in the given directory:
    >>> os.listdir(cwd)
    ['music', 'photos', 'memo.txt']
     

  • 相关阅读:
    java环境变量的配置
    usb转串口驱动时会出现“文件的哈希值不在指定的目录”这样的提示
    虚拟机安装tools for Ubuntu
    ubuntu 修改root密码
    旺旺自动回复
    android 启动流程
    ASCII 码表
    电脑中快速查找东西
    appengine 云计算。 部署web网络。
    openssl-0.9.8k_WIN32(RSA密钥生成工具
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10136219.html
Copyright © 2011-2022 走看看