zoukankan      html  css  js  c++  java
  • python 通过shutil实现文件后缀名判断及复制

    In [18]: for file in os.listdir('.'):
        ...:     if os.path.splitext(file)[1] == '.html':
        ...:         print(file)
        ...:         r=shutil.copy(file,os.path.join('Desktop',file+'3'))
        ...:         print('copy path is '+r)
        ...:
    index.html
    copy path is Desktopindex.html3

    获取扩展名和copy函数详解:

    In [21]: help(os.path.splitext)
    Help on function splitext in module ntpath:
    
    splitext(p)
        Split the extension from a pathname.
    
        Extension is everything from the last dot to the end, ignoring
        leading dots.  Returns "(root, ext)"; ext may be empty.
    
    
    In [22]: help(shutil.copy)
    Help on function copy in module shutil:
    
    copy(src, dst, *, follow_symlinks=True)
        Copy data and mode bits ("cp src dst"). Return the file's destination.
    
        The destination may be a directory.
    
        If follow_symlinks is false, symlinks won't be followed. This
        resembles GNU's "cp -P src dst".
    
        If source and destination are the same file, a SameFileError will be
        raised.
  • 相关阅读:
    主成分分析法
    K-means算法
    高斯混合模型
    data structure test
    八皇后问题求解
    商品管理系统课程设计
    哈佛商学院20部必看电影
    usaco1.1
    Visual Studio 2012 出现关于ActivityLog.xml错误的解决方案
    2012蓝桥杯决赛题
  • 原文地址:https://www.cnblogs.com/netsa/p/7805213.html
Copyright © 2011-2022 走看看