Board logo

Subject: 对临时文件清理有点意见 [Print This Page]

Author: niaoge    Time: 2007-8-23 15:26     Subject: 对临时文件清理有点意见

刚用cw文件清理时,有点意见,
cw能清理的文件类型多,但不代表多就好
比如刚才,我的第三方控件都方在一个文件夹下,本来想清掉dcu和一些~类型的文件,把不要的去掉,没想到拖动清理类型的滚动条
也没有注意到滚动条后面的(cw默认是选中的),结果不小心把.obj清掉了,完了,有要一个一个地加,obj文件
其实有很多第三方控件带.obj文件,所以.obj肯定不能放在清理选项中,就如不能把.pas,.dfm文件放在清理选项中
Author: Passion    Time: 2007-8-23 17:45

有些道理,不过obj也可能和dcu一样是编译生成的临时文件,这个确实不好区分。
要不吧obj文件的选项提前显示,并且默认不勾它吧。
Author: gz_runwe    Time: 2007-8-23 22:44

可以查找是否有同名的Pas或CPP文件,如果有源文件,obj文件当然可以删除,否则是否删除,通过CheckBox开关控制,默认不删除
Author: gz_runwe    Time: 2007-8-23 22:46

当然,以上规则,对dcu应该也适用,这样,就不能简单地删除所有*.dcu和*.obj了,而应该循环*.pas或*.cpp,删除其他文件
Author: yj_yulin    Time: 2007-8-25 12:13

同意gz_runwe

下面是我用的python脚本,

[Copy to clipboard]
CODE:
import os

def remove_file(file_name):
    try:
      os.remove(file_name)
      print '----------delete file:',file_name
    except:
      pass
  

   

for the_dir,sub_dir,file_list in os.walk('.'):
    print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
    print '>>>cd directory:',the_dir
    for file_name in file_list:
        print 'check file:',file_name
        
        if file_name.find('.~')>0 or file_name.find('.ddp')>0 or \
           file_name.find('.bak')>0 or file_name.find('.map')>0:
               remove_file(the_dir+os.sep+file_name)
               continue
           
        if file_name.find('.obj')>0: #remove when there has source file
            if os.path.exists(the_dir+os.sep+file_name.replace('.obj','.cpp')):
                remove_file(the_dir+os.sep+file_name)
                continue
            
        if file_name.find('.obj')>0: #remove when there has source file
            if os.path.exists(the_dir+os.sep+file_name.replace('.obj','.cxx')):
                remove_file(the_dir+os.sep+file_name)
                continue
               
        if file_name.find('.obj')>0: #remove when there has source file
            if os.path.exists(the_dir+os.sep+file_name.replace('.obj','.c')):
                remove_file(the_dir+os.sep+file_name)
                continue
               
        if file_name.find('.dcu')>0: #remove when there has source file
            if os.path.exists(the_dir+os.sep+file_name.replace('.dcu','.pas')):
                remove_file(the_dir+os.sep+file_name)
                continue
               


              
              
              


Author: Passion    Time: 2007-8-26 16:13

有些道理。不过对于专门设置了output路径的工程来说就有点不适应了。像CW的dcu都放dcu目录下,如果照同一目录下没相应源文件就不删除的规矩来的话,这个dcu就得不到机会清理了。
Author: Passion    Time: 2007-8-29 15:54

代码改过了,加了个checkbox,默认是不check的,也就是默认全删dcu/obj,第一次用需要手工勾选。
烦请等待unstable版本出来后帮我们验证验证。
Author: gz_runwe    Time: 2007-8-30 00:14     Subject: 谢谢老大啊


Author: Passion    Time: 2007-9-20 01:00

332的unstable版本增加了此复选框,烦请楼上各位验证。
http://www.cnpack.org/downbuilds.php?lang=zh-cn




Welcome to CnPack Forum (http://bbs.cnpack.org/) Powered by Discuz! 5.0.0