python大型项目包含哪些文件可以删除_Python 清理项目的目录

#-*- coding:utf-8 -*-

#=============================================

#

# author : yoshow

#

# filename : samples.clear.project.all.py

#

# summary : clear with project

#

#=============================================

import sys, os, stat

# 此脚本以删除.svn,bin,obj文件夹为例,删除某一文件雷同.

#

# Google一搜, 我发现网上有简单的方法,例如一下的shell命令.-_-

#

# window cmd

# for /r . %%a in (.) do @if exist "%%a.svn" rd /s /q "%%a.svn"

#

# linux shell

# find . -type f -iname ".svn" -exec rm -rf {} ;

def walk(path):

"""search files and directories."""

for item in os.listdir(path):

subpath=os.path.join(path, item)

mode=os.stat(subpath)[stat.ST_MODE]

if stat.S_ISDIR(mode):

view_child_dir = 1

# 此处填写你需要的删除的目录名称

list = ['.svn', 'debug', 'obj']

for dir_name in list :

if item.lower () == dir_name :

print "cleaning %s ..." % subpath

print "%d deleted" % purge(subpath)

view_child_dir = 0

#遍历子目录

if view_child_dir:

walk(subpath)

def purge(path):

"""purge mean clear some thing."""

count=0

for item in os.listdir(path):

subpath=os.path.join(path, item)

mode=os.stat(subpath)[stat.ST_MODE]

if stat.S_ISDIR(mode):

count+=purge(subpath)

else:

os.chmod(subpath, stat.S_IREAD|stat.S_IWRITE)

os.unlink(subpath)

count+=1

os.rmdir(path)

count+=1

return count

if __name__ == '__main__':

#get current project's directory.

path = os.path.normpath(os.getcwd())

#print path

walk(path)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值