把一个文件夹的文件备份到另一个文件夹

28 views
Skip to first unread message

fenghelong_njit

unread,
Apr 11, 2012, 1:37:59 PM4/11/12
to ZPyUG~珠三角地区Python用户组
我是在windows上的,把e盘的一个文件夹里的文件备份到同在e盘的另一个文件,但是却出现错误,不知道是怎么回事儿,现在把代码和错误帖在下
面。
code:
import os
import time
source=[r'e:\backup']
target_dir=[r'e:\satan']
today=target_dir+time.strftime('%Y%m%d')
now=time.strftime('%H%M%S')
if not os.paht.exists(today):
os.mkdir(today)
print 'successfully created directory',today
target=today+os.sep+now+'.zip'
zip_command="zip -qr '%s' %s" %(target,' '.join(source))
if os.system(zip_command)==0:
print 'successful backup to',target
else:
print 'back failed'

error:
Traceback (most recent call last):
File "C:/Users/fenghelong/Desktop/python操作/backup_ver2.py", line 5,
in <module>
today=target_dir+time.strftime('%Y%m%d')
TypeError: can only concatenate list (not "str") to list

Sutra Zhou

unread,
Apr 11, 2012, 10:07:00 PM4/11/12
to zp...@googlegroups.com
2012/4/12 fenghelong_njit <fenghel...@163.com>:

> 我是在windows上的,把e盘的一个文件夹里的文件备份到同在e盘的另一个文件,但是却出现错误,不知道是怎么回事儿,现在把代码和错误帖在下
> 面。
> code:
> import os
> import time
> source=[r'e:\backup']
> target_dir=[r'e:\satan']
这个是 list 呗
> today=target_dir+time.strftime('%Y%m%d')
time.strftime 是个字符串呗?
两个东西能用加号串接么?

> now=time.strftime('%H%M%S')
> if not os.paht.exists(today):
>    os.mkdir(today)
>    print 'successfully created directory',today
> target=today+os.sep+now+'.zip'
> zip_command="zip -qr '%s' %s" %(target,' '.join(source))
> if os.system(zip_command)==0:
>    print 'successful backup to',target
> else:
>    print 'back failed'
>
> error:
> Traceback (most recent call last):
>  File "C:/Users/fenghelong/Desktop/python操作/backup_ver2.py", line 5,
> in <module>
>    today=target_dir+time.strftime('%Y%m%d')
> TypeError: can only concatenate list (not "str") to list
>
> --
> '''邮件来自 `ZPyUG`--珠三角地区Python用户组 列表
> 详情: https://groups-beta.google.com/group/zpug
> 发言: zp...@googlegroups.com
> 退订: zpug-uns...@googlegroups.com
> 维基: http://wiki.woodpecker.org.cn/moin/ZPyUG
> 中国事务: https://groups.google.com/group/CPUG
> 北京事务: https://groups.google.com/group/bpug
> 上海事务: https://groups.google.com/group/spug
> 安徽事务: https://groups.google.com/group/ahpug
> 东南事务: https://groups.google.com/group/cpug-eastchina
> 技术列表: https://groups.google.com/group/python-cn
> '''
Reply all
Reply to author
Forward
0 new messages