python对文件夹的一些操作,,复制文件夹def Cop
python对文件夹的一些操作,,复制文件夹def Cop
复制文件夹
def CopyFolderOs(sFolder,tFolder): sourcePath = sFolder destPath = tFolder for root, dirs, files in os.walk(sourcePath): #figure out where we're going dest = destPath + root.replace(sourcePath, '') #if we're in a directory that doesn't exist in the destination folder #then create a new folder if not os.path.isdir(dest): os.mkdir(dest) print 'Directory created at: ' + dest #loop through all files in the directory for f in files: #compute current (old) & new file locations oldLoc = root + '\\' + f newLoc = dest + '\\' + f if not os.path.isfile(newLoc): try: shutil.copy2(oldLoc, newLoc) print 'File ' + f + ' copied.' except IOError: print 'file "' + f + '" already exists'
删除文件夹
def RemoveFolderOs(sourceDir,localAppDataPath): for root, dirs, files in os.walk(sourceDir): for f in files: os.unlink(os.path.join(root, f)) for d in dirs: shutil.rmtree(os.path.join(root, d))
相关内容
- Python 版的 PinkTrace 示例 pink-simple-strace-linux.py,,pink-si
- Python 版的 PinkTrace 示例 pink-fork-linux.py,,pink-fork-li
- 支持GAE本地运行的Unit test基类,gaeunit,GaeTestCase#
- 显示距离下班还有多长时间的Python版,多长时间python
- 各种排序方法,排序方法,最近找工作,很是郁闷,回
- python编写的一个通过多线程扫描端口的代码,python多线
- 用wxpython开发的批量在图片上生成水印文字的可视化小
- 打印日历,,python代码#-*-
- GAE/python中利用memcache代替Session实现用户登录验,gaeme
- 获得图片的Base64编码,,python代码#!/u
评论关闭