Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Created November 9, 2012 03:53
Show Gist options
  • Save naoyeye/4043592 to your computer and use it in GitHub Desktop.
Save naoyeye/4043592 to your computer and use it in GitHub Desktop.
class post_image_delete:
@session.login_required
def POST(self, arg):
data = web.input()
path = data.path # 类似 '/static/upload/post_img/2012/11/9'
part_name = data.part_name # 类似 '201211981222_7a214d288112fe8ef99944aa7ce4d228'
homedir = os.getcwd()
imgPath = homedir + path
#上面组装的结果类似这样 : "/home/www/rhinocero" + "/static/upload/post_img/2012/11/9"
if os.path.isfile(imgPath + '/.DS_Store'): #为防止mac系统下的.DS_Store捣乱,先删除它
os.remove(imgPath + '/.DS_Store')
files = os.listdir(imgPath) #得到imgPath下的所有文件
for file in files:
p = file.split('.')[0] # 结果类似: 201211981222_7a214d288112fe8ef99944aa7ce4d228_1200
p2 = p.split('_',2)[0] # 结果类似: 201211981222
p3 = p.split('_',2)[1] # 结果类似: 7a214d288112fe8ef99944aa7ce4d228
if p2+'_'+p3 == part_name:
file = imgPath + "/" + file
os.remove(file)
success = "s"
return success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment