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+''))
...: print('copy path is '+r)
...:
index.html
copy path is Desktop\index.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.

python 通过shutil实现文件后缀名判断及复制的更多相关文章

  1. js 上传文件后缀名的判断 var flag=false;应用

    js 上传文件后缀名的判断  var flag=false;应用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...

  2. [Java] 03 String获取文件后缀名,判断文件是否合法

    package test.string; import java.util.Arrays; import java.util.List; public class GetFileType { priv ...

  3. shell提取文件后缀名,并判断其是否为特定字符串

    如果文件是 .css文件 或 .js文件,则进行处理. file=$1 if [ "${file##*.}"x = "css"x ]||[ "${fi ...

  4. shell判断文件后缀名是否为特定字符串

    如果文件是 .css文件 或 .js文件,则进行处理. if [ "${file##*.}"x = "css"x ]||[ "${file##*.}& ...

  5. python应用-获取文件后缀名

    def get_suffix(filename,has_dot=False): """ 获取文件后缀名 :param filename: 文件名 :param has_d ...

  6. python修改文件后缀名

    修改文件后缀名 # -*- coding: utf-8 -*- import os # # 列出当前目录下所有的文件 # filedir = 'C:\\Users\\WT\\Desktop\\test ...

  7. php上传功能集后缀名判断和随机命名

    form.php <html> <head> <meta http-equiv="content-type" content="text/h ...

  8. Linux下的文件及文件后缀名

    Linux下的文件及文件后缀名 2013-03-14 15:34 6969人阅读 评论(0) 收藏 举报 ++++++++++++++++++++++++++++++++++++++正文+++++++ ...

  9. Python3 批量更改文件后缀名

    Python3 批量更改文件后缀名 示例: # coding:utf8 import os import sys def Rename(): #Path = "F:\\test\\" ...

随机推荐

  1. 多线程系列(3)任务Task

    虽然使用线程池ThreadPool让我们使用多线程变得容易,但是因为是由系统来分配的,如果想对线程做精细的控制就不太容易了,比如某个线程结束后执行一个回调方法.恰好Task可以实现这样的需求.这篇文章 ...

  2. Liunx下配置网络

    1.首先查看一下自己的网络 ifconfig 我查看之后发现....没有eth0 ok,现在去 /etc/sysconfig/network-scripts 目录中查看是否有 ifcfg-et0 文件 ...

  3. POJ2236(KB5-A)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 28617   Accepted: 118 ...

  4. HTTPS的安全性

    一.Https介绍 1. 什么是Https HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道, ...

  5. 【读书笔记】iOS-定位服务与地图应用开发

    一,定位服务. iOS设备能提供3种不同的定位途径: 1,WiFi定位,通过查询一个WiFi路由器的地理位置的信息,比较省电:iPhone,Ipod touch 和iPad都可以. 2,蜂窝式移动电话 ...

  6. 【代码笔记】iOS-NSLog的使用

    代码: // 在debug模式下输出NSLog,在release模式下不输出NSLog #ifndef __OPTIMIZE__ #define NSLog(...) NSLog(__VA_ARGS_ ...

  7. MBTIles实现

    MBTIles实现 3.1 Compliant(符合) python: raster2mb (write) python: mbutil (read/write) python: landez (wr ...

  8. LeetCode题解之Maximum Depth of N-ary Tree

    1.题目描述 2.问题分析 利用递归fangf 3.代码 int maxDepth(Node* root) { int res = maxdep(root); return res; } int ma ...

  9. [转载]Buffer cache的调整与优化

    Buffer Cache是SGA的重要组成部分,主要用于缓存数据块,其大小也直接影响系统的性能.当Buffer Cache过小的时候,将会造成更多的free buffer waits事件.下面将具体描 ...

  10. Innodb页面存储结构-2

    上一篇<Innodb页面存储结构-1>介绍了Innodb页面存储的总体结构,本文会介绍页面的详细内容,主要包括页头.页尾和记录的详细格式. 学习数据结构时都说程序等于数据结构+算法,而在i ...