找回密码
 加入
搜索
查看: 4429|回复: 13

如何监视一个文件夹,一旦文件夹中有exe文件就能获取其文件名

 火.. [复制链接]
发表于 2010-1-18 20:46:52 | 显示全部楼层 |阅读模式
本帖最后由 haorui658 于 2010-1-19 21:10 编辑

如题,监视文件夹,文件夹的路径已知,当文件夹内只有一个文件,且该文件为可执行文件时,获取其文件名.以此来达到自动化执行的目的.

评分

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

查看全部评分

发表于 2010-1-19 09:38:09 | 显示全部楼层
这样应该可以吧!
$Path = @ScriptDir&'\hotfix'
$search = FileFindFirstFile($Path&'\*.exe')

If $search = -1 Then
    MsgBox(0, "错误", "没有文件/目录 匹配搜索")
    Exit
EndIf

While 1
        $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    MsgBox(4096, "发现可执行文件!", $file)
WEnd
FileClose($search)
发表于 2010-1-19 10:04:20 | 显示全部楼层
这样应该可以吧!
水木子 发表于 2010-1-19 09:38



    会使CPU使用率占用过高吧???
发表于 2010-1-19 11:13:14 | 显示全部楼层
本帖最后由 maxkingmax 于 2010-1-19 12:43 编辑
#include<file.au3>
$path= @ScriptDir&'\hotfix'
While 1
Sleep(1000)
$exearray=_FileListToArray($path,"*.exe",1)
        If IsArray($exearray) Then
                For $i=1 To $exearray[0]
                        MsgBox(0,"Find exe file "&$i,$path&'\'&$exearray[$i],3)
                        Next
        EndIf
WEnd
 楼主| 发表于 2010-1-19 12:57:20 | 显示全部楼层
本帖最后由 haorui658 于 2010-1-19 12:59 编辑

回复 4# maxkingmax


    谢谢你们的回答,在监视的同时本程序还在运行做其他的事,但是一旦发现该目录有执行文件就执行这个文件.最好能给出思路和关键函数,能给出示例的源码更好.
发表于 2010-1-19 13:07:54 | 显示全部楼层
回复 5# haorui658


    AdlibRegister ( "监视函数" )
发表于 2010-1-19 13:25:45 | 显示全部楼层
#include<file.au3>



$path= @ScriptDir&'\hotfix'

AdlibRegister("autorunexe",5000) ;5秒钟检查一下指定目录,有EXe就执行

While 1
Sleep(100);让程序做其他的事吧

WEnd

Func autorunexe()
        $exearray=_FileListToArray($path,"*.exe",1)
        If IsArray($exearray) Then
                For $i=1 To $exearray[0]
                        Run($path&'\'&$exearray[$i])
                                Next
        EndIf
EndFunc
发表于 2010-1-19 13:56:52 | 显示全部楼层
条条大路通罗马
 楼主| 发表于 2010-1-19 13:59:21 | 显示全部楼层
本帖最后由 haorui658 于 2010-1-19 21:10 编辑

恩 感谢maxkingmax  这就是我想要的,到时实验一下 呵呵
 楼主| 发表于 2010-1-19 21:10:38 | 显示全部楼层
OK 没有问题 感谢所有给我提供过帮助的人
发表于 2010-1-31 10:59:03 | 显示全部楼层
感谢以上的大侠
发表于 2011-6-30 10:12:17 | 显示全部楼层
进来 学习一下!
发表于 2011-6-30 15:02:49 | 显示全部楼层
学习~已经收藏
发表于 2011-7-8 15:01:55 | 显示全部楼层
有用到..謝謝
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-1 23:37 , Processed in 0.080047 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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