找回密码
 加入
搜索
查看: 3897|回复: 12

[AU3基础] [已解决]使用Filedelete能否删除某一目录下的所有文件或者某一类文件?

 火.. [复制链接]
发表于 2010-11-1 08:34:55 | 显示全部楼层 |阅读模式
本帖最后由 smooth 于 2010-11-9 22:37 编辑

使用Filedelete能否删除某一目录下的所有文件或者某一类文件?比如:

C:\Documents and Settings\Administrator\Application Data\*.exe

谢谢。

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-11-1 10:22:31 | 显示全部楼层
完全没问题的,楼主,
示例/演示
FileDelete("D:\*.exe")
删除D盘下的所有exe文件
发表于 2010-11-1 13:23:05 | 显示全部楼层
哈哈。要自己试试就知道了。
 楼主| 发表于 2010-11-1 16:40:24 | 显示全部楼层
本帖最后由 smooth 于 2010-11-1 16:48 编辑

我测试的,只能删除根目录的文件,子目录的文件并没有删除,不知道为什么。
$search = FileFindFirstFile(@AppDataCommonDir & "\*.exe")
While 1
           $file = FileFindNextFile($search)
    If @error Then ExitLoop
        FileDelete(@AppDataCommonDir & "\" & $file)
WEnd
FileClose($search)

或者:
FileDelete(@AppDataCommonDir & "\*.exe")

或者:
FileDelete("C:\Documents and Settings\All Users\Application Data\*.exe")

都是只能删除C:\Documents and Settings\All Users\Application Data目录下的exe文件,
不能删除这个目录的子目录中的exe文件,不晓得为啥了。
发表于 2010-11-1 17:58:32 | 显示全部楼层
搜搜udf区,有的是方法
 楼主| 发表于 2010-11-1 18:40:50 | 显示全部楼层
回复 5# netegg
我去看看,谢谢。
发表于 2010-11-2 08:48:30 | 显示全部楼层
有些文件当前正在运行调用,肯定人删除不掉的啦。。
发表于 2010-11-2 09:54:43 | 显示全部楼层
可以采用递归的方法来实现的
 楼主| 发表于 2010-11-2 16:18:40 | 显示全部楼层
回复 8# h20040606

愿闻其详呀。
发表于 2010-11-2 16:25:33 | 显示全部楼层
先 dir /b/s > filelist.txt
然后 readline filelist.txt
发表于 2010-11-2 17:07:47 | 显示全部楼层
Func __deletefile($path,$ext)
$search = FileFindFirstFile($path &"\" & $ext)
While 1
           $file = FileFindNextFile($search)
    If @error Then ExitLoop
        If FileGetAttrib($path & "\" $file)="D" Then
                        __deletefile($path & "\" $file,$ext)
                        Else
                    FileDelete($path &"\" $file)
             EndIf
WEnd
FileClose($search)


EndFunc
发表于 2010-11-2 18:39:43 | 显示全部楼层
Filedelete能删除文件夹里的所有文件或者某一类文件.
 楼主| 发表于 2010-11-9 22:33:45 | 显示全部楼层
本帖最后由 smooth 于 2010-11-9 22:36 编辑

搞定了!
#include <File.au3>
#include <GuiListBox.au3>
#include <WindowsConstants.au3>

Findfile(@TempDir)
Func Findfile($Path)
        $aFileList = _FileListToArray($Path)
        If Not @error Then
                For $i = 1 To $aFileList[0]
                        DirRemove($Path & '\' & $aFileList[$i], 1)
                        FileDelete($Path & '\' & $aFileList[$i])
                Next
        EndIf
EndFunc   ;==>Findfile
这样是删除TempDir目录下所有文件和文件夹
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-3 02:25 , Processed in 0.089842 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表