def stripFile(oldFile, newFile): '''remove the space or Tab or enter in a file, and output a new file in the same folder''' f = open(oldFile, 'r+', encoding='utf8') newf = open(newFile, 'w',encoding='utf8') for eachline in f.readlines(): newStr = eac
原文 : http://www.cnblogs.com/SophiaTang/archive/2012/01/16/2323467.html import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.removedirs() 递归删除目录和文件(类似DOS命令DeleteTree): 方法1:自力更生,艰苦创业 # Delete everything reachable from the directory named in 'top',
import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.removedirs() 递归删除目录和文件(类似DOS命令DeleteTree): 方法1:自力更生,艰苦创业 # Delete everything reachable from the directory named in 'top',# assuming there are no symbolic links.# CAUTION: This is dangerous!
删除qq文件夹中2013年12-31之前的文件import os import time import datetime timeline = datetime.datetime(,,) tl = time.mktime(timeline.timetuple()) rootdir = r'C:\Documents and Settings\Administrator.CHINA-C58199F8B\My Documents\Tencent Files\xxxxxxxx\Image' for ba
将文本中的 tasting123删除 with open("fileread.txt","r",encoding="utf-8") as f: lines = f.readlines() #print(lines) with open("fileread.txt","w",encoding="utf-8") as f_w: for line in lines: if "tast
import shutil with open('/path/to/file', 'r') as f: with open('/path/to/file.new', 'w') as g: for line in f.readlines(): if '/local/server' not in line: g.write(line) shutil.move('/path/to/file.new', '/path/to/file') 原文链接:https://segmentfault.com/q/1