#os 模块os.sep 可以取代操作系统特定的路径分隔符。windows下为 '\\'
os.name 字符串指示你正在使用的平台。比如对于Windows,它是'nt',而对于Linux/Unix用户,它是 'posix'
os.getcwd() 函数得到当前工作目录,即当前Python脚本工作的目录路径
os.getenv() 获取一个环境变量,如果没有返回none
os.putenv(key, value) 设置一个环境变量值
os.listdir(path) 返回指定目录下的所有文件和目录名
os.remove(path) 函数用来删除一个文件
os.system(command) 函数用来运行shell命令
os.linesep 字符串给出当前平台使用的行终止符。例如,Windows使用 '\r\n',Linux使用 '\n' 而Mac使用 '\r'
os.path.split(path)  函数返回一个路径的目录名和文件名
os.path.isfile() 和os.path.isdir()函数分别检验给出的路径是一个文件还是目录
os.path.exists() 函数用来检验给出的路径是否真地存在
os.curdir  返回当前目录 ('.')
os.mkdir(path) 创建一个目录
os.makedirs(path) 递归的创建目录
os.chdir(dirname) 改变工作目录到dirname
os.path.getsize(name) 获得文件大小,如果name是目录返回0L
os.path.abspath(name) 获得绝对路径
os.path.normpath(path) 规范path字符串形式
os.path.splitext()  分离文件名与扩展名
os.path.join(path,name) 连接目录与文件名或目录
os.path.basename(path) 返回文件名
os.path.dirname(path) 返回文件路径
os.walk(top,topdown=True,οnerrοr=None)  遍历迭代目录
os.rename(src, dst)  重命名file或者directory src到dst 如果dst是一个存在的directory, 将抛出OSError. 在Unix, 如果dst在存且是一个file, 如果用户有权限的话,它将被安静的替换. 操作将会失败在某些Unix 中如果src和dst在不同的文件系统中. 如果成功, 这命名操作将会是一个原子操作 (这是POSIX 需要). 在 Windows上, 如果dst已经存在, 将抛出OSError,即使它是一个文件. 在unix,Windows中有效。
os.renames(old, new) 递归重命名文件夹或者文件。像rename()# shutil 模块
shutil.copyfile( src, dst) 从源src复制到dst中去。当然前提是目标地址是具备可写权限。抛出的异常信息为IOException. 如果当前的dst已存在的话就会被覆盖掉
shutil.move( src, dst)  移动文件或重命名
shutil.copymode( src, dst) 只是会复制其权限其他的东西是不会被复制的
shutil.copystat( src, dst) 复制权限、最后访问时间、最后修改时间
shutil.copy( src, dst)  复制一个文件到一个文件或一个目录
shutil.copy2( src, dst)  在copy上的基础上再复制文件最后访问时间与修改时间也复制过来了,类似于cp –p的东西
shutil.copy2( src, dst)  如果两个位置的文件系统是一样的话相当于是rename操作,只是改名;如果是不在相同的文件系统的话就是做move操作
shutil.copytree( olddir, newdir, True/Flase)
把olddir拷贝一份newdir,如果第3个参数是True,则复制目录时将保持文件夹下的符号连接,如果第3个参数是False,则将在复制的目录下生成物理副本来替代符号连接
shutil.rmtree( src ) 递归删除一个目录以及目录内的所有内容

NAME
    shutil - Utility functions for copying and archiving files and directory trees.

FILE
    /usr/lib/python2.7/shutil.py

MODULE DOCS
    http://docs.python.org/library/shutil

DESCRIPTION
    XXX The functions here don't copy the resource fork or other metadata on Mac.

CLASSES
    exceptions.EnvironmentError(exceptions.StandardError)
        Error
        ExecError
        SpecialFileError
    
    class Error(exceptions.EnvironmentError)
     |  Method resolution order:
     |      Error
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:

|  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.EnvironmentError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:

|  
     |  __dict__
     |  
     |  args
     |  
     |  message
    
    class ExecError(exceptions.EnvironmentError)
     |  Raised when a command could not be executed
     |  
     |  Method resolution order:
     |      ExecError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror

|  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.EnvironmentError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message

class SpecialFileError(exceptions.EnvironmentError)
     |  Raised when trying to do a kind of operation (e.g. copying) which is
     |  not supported on a special file (e.g. a named pipe)
     |  
     |  Method resolution order:
     |      SpecialFileError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror

----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.EnvironmentError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message

FUNCTIONS
    copy(src, dst)
        Copy data and mode bits ("cp src dst").
        
        The destination may be a directory.

copyfile(src, dst)
        Copy data from src to dst
    
    copyfileobj(fsrc, fdst, length=16384)
        copy data from file-like object fsrc to file-like object fdst
    
    copymode(src, dst)
        Copy mode bits from src to dst
    
    copystat(src, dst)
        Copy all stat info (mode bits, atime, mtime, flags) from src to dst
    
    copytree(src, dst, symlinks=False, ignore=None)
        Recursively copy a directory tree using copy2().
        
        The destination directory must not already exist.
        If exception(s) occur, an Error is raised with a list of reasons.
        
        If the optional symlinks flag is true, symbolic links in the
        source tree result in symbolic links in the destination tree; if
        it is false, the contents of the files pointed to by symbolic
        links are copied.
        
        The optional ignore argument is a callable. If given, it
        is called with the `src` parameter, which is the directory
        being visited by copytree(), and `names` which is the list of
        `src` contents, as returned by os.listdir():
        
            callable(src, names) -> ignored_names
        
        Since copytree() is called recursively, the callable will be
        called once for each directory that is copied. It returns a
        list of names relative to the `src` directory that should
        not be copied.
        
        XXX Consider this example code rather than the ultimate tool.
    
    get_archive_formats()
        Returns a list of supported formats for archiving and unarchiving.
        
        Each element of the returned sequence is a tuple (name, description)
    
    ignore_patterns(*patterns)

Function that can be used as copytree() ignore parameter.
        
        Patterns is a sequence of glob-style patterns
        that are used to exclude files
    
    make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0, dry_run=0, owner=None, group=None, logger=None)
        Create an archive file (eg. zip or tar).
        
        'base_name' is the name of the file to create, minus any format-specific
        extension; 'format' is the archive format: one of "zip", "tar", "bztar"
        or "gztar".
        
        'root_dir' is a directory that will be the root directory of the
        archive; ie. we typically chdir into 'root_dir' before creating the
        archive.  'base_dir' is the directory where we start archiving from;
        ie. 'base_dir' will be the common prefix of all files and
        directories in the archive.  'root_dir' and 'base_dir' both default
        to the current directory.  Returns the name of the archive file.
        
        'owner' and 'group' are used when creating a tar archive. By default,
        uses the current owner and group.
    
    move(src, dst)
        Recursively move a file or directory to another location. This is
        similar to the Unix "mv" command.
        
        If the destination is a directory or a symlink to a directory, the source
        is moved inside the directory. The destination path must not already
        exist.
        
        If the destination already exists but is not a directory, it may be
        overwritten depending on os.rename() semantics.
        
        If the destination is on our current filesystem, then rename() is used.
        Otherwise, src is copied to the destination and then removed.
        A lot more could be done here...  A look at a mv.c shows a lot of
        the issues this implementation glosses over.
    
    register_archive_format(name, function, extra_args=None, description='')
        Registers an archive format.
        
        name is the name of the format. function is the callable that will be
        used to create archives. If provided, extra_args is a sequence of
        (name, value) tuples that will be passed as arguments to the callable.
        description can be provided to describe the format, and will be returned
        by the get_archive_formats() function.

rmtree(path, ignore_errors=False, οnerrοr=None)
        Recursively delete a directory tree.
        
        If ignore_errors is set, errors are ignored; otherwise, if onerror
        is set, it is called to handle the error with arguments (func,
        path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
        path is the argument to that function that caused it to fail; and
        exc_info is a tuple returned by sys.exc_info().  If ignore_errors
        is false and onerror is None, an exception is raised.
    
    unregister_archive_format(name)

DATA
    __all__ = ['copyfileobj', 'copyfile', 'copymode', 'copystat', 'copy', ...

os模块中的shutil的使用方式与方法相关推荐

  1. python中的os.mkdir和os.makedirs的使用区别,以及如何查看某个模块中的某些字母开头的属性方法

    1 os.mkdir的使用 os.mkdir(dir_name):用于新建文件夹,当要新建的文件夹已经存在的时候,就会报错:FileExistsError: [Errno 17] File exist ...

  2. python os复制文件_使用python os模块复制文件到指定文件夹的方法

    复制一个文件夹的文件到指定目录下 import os import shutil import time start_time = time.time() # 需要被复制的文件夹 old_path = ...

  3. 苹果系统 如何快速访问服务器,在Mac OS X中快速访问4种方式的根目录 | MOS86

    像其他形式的unix一样,Mac OS X的根目录只是/,但是从Finder还可以使用主硬盘驱动器的名称.默认情况下是Macintosh HD,较新版本的OS X已经开始隐藏用户的根文件夹,因为大多数 ...

  4. TP6中db操作数据库的方式(方法)和ORM模型操作数据库的方式(方法)

    db库认知基础 注:orm独立出来了,与tp5不同 配置数据库: 通过env文件来具体配置,目的是不同的环境下,如线上服务器的配置只需要使用本环境的env文件就可以直接更改配置了 使用db: ① tp ...

  5. 获取SAP HR模块中员工照片及照片URL的方法

    SAP提供了2个标准函数,直接调用即可. HR_ESS_WHO_PROG_GET_PICT_URI HR_ESS_WHO_PROG_GET_PICTURE

  6. Python模块——os模块详解

    本文大纲 os模块是Python中整理文件和目录最为常用的模块,该模块提供了非常丰富的方法用来处理文件和目录.本着只讲最有用的态度,下方我将os模块中一些我经常用的的方法,给大家详细列举出来了,希望减 ...

  7. Python-22 文件系统:os模块

    模块 >>> random,randint(1,10) Traceback (most recent call last):File "<pyshell#0>& ...

  8. shutil模块,为什么说它是os模块的兄弟模块?

    本文大纲 os模块是Python标准库中一个重要的模块,里面提供了对目录和文件的一般常用操作.而Python另外一个标准库--shutil模块,它作为os模块的补充,提供了复制.移动.删除.压缩.解压 ...

  9. python中的os abort_Python::OS 模块 -- 进程管理

    这里我们介绍os模块中的进程管理相关的操作. os模块提供给了我们访问操作系统功能的接口,我们可以通过os模块提供给我们的进程管理接口,编写多进程程序,这对编写高效.并发的程序提供了方便. 下面是一个 ...

最新文章

  1. PaddleOCR,一款文本识别效果不输于商用的Python库!
  2. [WUST2017]一组简单一点的题目(三) A - Calculate S(n)
  3. 用策略屏蔽135 139 445 3389端口+网络端口安全防护技
  4. nginx 配置文件参数说明
  5. FFMPEG使用参数详解
  6. 修改Hybris Administration console管理员默认登录密码
  7. 软件安全测试报告模板_软件测试工程师经典面试题
  8. c# 带返回值的action_C#委托的介绍(delegate、Action、Func、predicate)
  9. 用JS创建一个XML文件
  10. 查询端口被什么程序占用及停止的方法及netstat的妙用
  11. WINDOWS操作系统32位(x86)和64位(x64)的区别
  12. 关于移动开发的一些meta设置
  13. 帅瞎了!手机也能写Python代码!手把手教你在手机或平板上配置Python环境!
  14. 伺服电机常用参数设置_松下伺服几个参数需要熟悉并掌握设置方法
  15. hdu 4585 Shaolin两种方法(暴力和STL map set)
  16. fastadmin保持用户登陆状态
  17. 认识Python继承:super()
  18. TextPad安装环境配置
  19. 浏览器预览Excel、PPT、Word
  20. tomcat如何编译java_tomcat怎么编译java

热门文章

  1. hdu 3572(最大流)
  2. NYOJ 990 蚂蚁感冒
  3. 【LuoguP33294123】[ZJOI2011]最小割[CQOI2016]不同的最小割
  4. sqli-labs(十三)(hpp)
  5. iometer测试工具
  6. 转: eclipse 快捷键列表(功能清晰版本)
  7. [动规] hihocoder 1149 回文字符序列
  8. 为HttpStatusCodeResult加入customErrors
  9. Deep Learning学习 之 CNN代码解析(MATLAB)
  10. 基于VTK与Qt的体绘制程序