python对文件夹的一些操作,python文件夹操作,python文件夹的一些
python对文件夹的一些操作,python文件夹操作,python文件夹的一些
python文件夹的一些操作
复制文件夹
删除文件夹
#复制文件夹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))#该片段来自于http://byrx.net
相关内容
- Python 简单的记事本,Python简单记事本,这个程序只实现
- Python 简单的计算器,Python简单计算器,Python完成的一个
- 把整数转为二进制,整数转为二进制,把整数转为二进制
- Python 版的 PinkTrace 示例 pink-fork-linux.py,,#!/usr/bin/e
- Py4J 示例代码 (Python 调用 Java API),py4jpython,这段代码
- 对文件进行编码转换,文件进行编码转换,import sysim
- 将 HTML 文件转成指定的编码,html编码,import sysim
- 加载二进制文件到 CkByteArray 对象,二进制ckbytearray,im
- 在字节数组中搜索 findBytes,数组findbytes,import chilk
- removeChunk - remove a subrange from a byte array.,,Remove a chu
评论关闭