python对文件夹的一些操作
来源:互联网 发布:淘宝地址武汉没有汉口 编辑:程序博客网 时间:2024/03/29 22:21
代码片段(2)
[代码] 复制文件夹
01
def
CopyFolderOs(sFolder,tFolder):
02
sourcePath
=
sFolder
03
destPath
=
tFolder
04
for
root, dirs, files
in
os.walk(sourcePath):
05
06
#figure out where we're going
07
dest
=
destPath
+
root.replace(sourcePath, '')
08
09
#if we're in a directory that doesn't exist in the destination folder
10
#then create a new folder
11
if
not
os.path.isdir(dest):
12
os.mkdir(dest)
13
print
'Directory created at: '
+
dest
14
15
#loop through all files in the directory
16
for
f
in
files:
17
18
#compute current (old) & new file locations
19
oldLoc
=
root
+
'\\'
+
f
20
newLoc
=
dest
+
'\\'
+
f
21
22
if
not
os.path.isfile(newLoc):
23
try
:
24
shutil.copy2(oldLoc, newLoc)
25
print
'File '
+
f
+
' copied.'
26
except
IOError:
27
print
'file "'
+
f
+
'" already exists'
[代码] 删除文件夹
1
def
RemoveFolderOs(sourceDir,localAppDataPath):
2
for
root, dirs, files
in
os.walk(sourceDir):
3
for
f
in
files:
4
os.unlink(os.path.join(root, f))
5
for
d
in
dirs:
6
shutil.rmtree(os.path.join(root, d))
http://www.oschina.net/code/snippet_72895_1576
- python对文件夹的一些操作
- python对文件,文件夹的一些操作
- Python对文件及文件夹的一些操作
- python对文件及文件夹的一些操作
- python对文件及文件夹的一些操作
- PYTHON对文件及文件夹的一些操作
- python对文件及文件夹的一些操作
- python对文件及文件夹的一些操作
- PYTHON对文件及文件夹的一些操作
- python对文件及文件夹的一些操作
- 【Python】Python对文件夹的操作
- Python文件及文件夹的一些操作
- python对文件及文件夹的操作
- python中对文件、文件夹的操作
- python中对文件、文件夹的操作
- python中对文件、文件夹的操作
- python中对文件、文件夹的操作
- python 中对文件、文件夹的操作
- Java 之 回调函数实例说明
- 汇编指令
- 【开发者观点】Web App和Native App,谁会是未来的主流移动趋势?
- 述职报告范文
- android代码库之textview跑马灯效果
- python对文件夹的一些操作
- 技术人员述职报告
- HTML5(目前)无法帮你实现的五件事
- 【观点】我们在构建一个臃肿而缓慢的Web网络
- finalize方法的几点理解
- Python 随机生成中文验证码
- 移动web上的无处不在原则
- 基于QT的时钟模拟程序
- 黑盒测试准备