勤&快

问题其实就是你期望的东西和你体验的东西之间的差别
随笔 - 55, 文章 - 0, 评论 - 68, 引用 - 0
数据加载中……

python从一个文件夹自动拷贝文件到目标文件夹

自己刚接触python,参考网上一个教程写的。记录一下。

# Filename: CopyPictures.py

import os
import time
from os import listdir
from os.path import isdir
#source = ['/home/swaroop/byte', '/home/swaroop/bin']
source = 'C:\\Program Files\\Coopen\\image\\image_100042'
target_dir 
= 'D:\\My Documents\\My Pictures\\my'
now 
= time.strftime('%Y%m%d')
if isdir(source) != True:
    
print 'Error: source is not a directory'
    exit()
k
=0
filelist 
= listdir(source)
print(filelist)
= 0
for name in filelist :
    
if name.find('jpg'== -1 and name.find('png'== -1 :
        
del(filelist[t])
    t 
= t + 1
print(filelist)
#exit()
for name in filelist :
    srcFilename 
= source + '\\' + name
    srcFilename 
= '"' + srcFilename + '"'
    desFilename 
= target_dir + '\\' + now + '_' + name
    desFilename 
= '"' + desFilename + '"'
    
print 
    copy_command 
= "copy %s %s" % (srcFilename, desFilename)
    
print copy_command
    
if os.system(copy_command) == 0:
        k 
= k + 1
        
print 'Successful backup to copy from', srcFilename, 'to' ,desFilename
    
else:
        
print 'Fail to copy', srcFilename, 'to', desFilename
print 'total copy', k, 'files'

posted on 2007-04-26 13:50 daning 阅读(6771) 评论(4)  编辑  收藏 所属分类: others

评论

# re: python从一个文件夹自动拷贝文件到目标文件夹  回复  更多评论   

怎么变成可执行文件
2008-01-11 16:36 | 暗暗

# re: python从一个文件夹自动拷贝文件到目标文件夹  回复  更多评论   

py2exe
2008-07-01 10:46 | wnxwf

# re: python从一个文件夹自动拷贝文件到目标文件夹[未登录]  回复  更多评论   

大家好,我想从C:\PHOENIX\Log\Image文件夹里面复制一个变量的图片到C:\PHOENIX\AKT文件夹里面,请问用Python怎么写,求大神!谢谢.
2015-08-29 16:44 | 小丁

# re: python从一个文件夹自动拷贝文件到目标文件夹  回复  更多评论   

python怎么做成 exe
2015-08-31 19:53 | md5免费查询

只有注册用户登录后才能发表评论。


网站导航: