找回密码
 加入
搜索
楼主: xavier880819

使用autoIT调用bat文件的问题

[复制链接]
发表于 2009-7-29 15:51:41 | 显示全部楼层
呵呵,你都不知道哪里变了我还能知道吗,呵呵
其实删除可以调用Dos命令,Windows下面删除太慢了,Dos下面快N倍,特别是几千上万的文件及目录更明显
 楼主| 发表于 2009-7-29 17:02:54 | 显示全部楼层
呵呵,我知道为什么了,是因为在目标文件夹没有选择的情况下删除就会出现那种情况了。

对了,你说的再Dos下面删除又是怎么一回事呢??我觉得在windows下面删除,直接删除文件夹确实比较慢,但是如果删除有文件的文件夹就快很多了。
发表于 2009-7-29 19:32:41 | 显示全部楼层
#include <Process.au3>
_RunDOS ( $sCommand );$sCommand 为一个 DOS 命令.比如 'rd F /s /q'
 楼主| 发表于 2009-7-30 09:22:27 | 显示全部楼层
63# afan


嘿嘿,只要是新方法我就愿意去尝试一下。谢谢你!
 楼主| 发表于 2009-8-5 13:41:12 | 显示全部楼层
请教一下afan

如果说我复制的文件夹里面的文件,我需要设定成只复制某一种格式的文件,需要用什么做到呢?
发表于 2009-8-5 14:38:34 | 显示全部楼层
那就需要一个搜索的前奏了,如果文件较多,那就先遍历搜索需要的文件到一临时文件,一行一个路径。
之后在复制时加一个循环,FileReadLine 逐行读取源文件并复制到目标文件夹。
 楼主| 发表于 2009-8-5 17:59:42 | 显示全部楼层
66# afan


不是很明白,可不可以有个小例子?这样比较容易理解点,谢谢
发表于 2009-8-5 19:06:55 | 显示全部楼层
写了一段,这个例子就是搜索 E:\music 下面(含子目录)的mp3文件,复制到 C:\1 里面。
#include <File.au3>
$sslj = 'E:\Music'
$fh = FileOpen(@ScriptDir & "\1.txt", 1)
_filelist($sslj, '.mp3')
FileClose($fh)

$fh = FileOpen(@ScriptDir & "\1.txt", 0)
While 1
        $rl = FileReadLine($fh)
        If @error = -1 Then ExitLoop
        FileCopy($rl, 'c:\1\', 9)
WEnd
FileClose($fh)
FileDelete(@ScriptDir & "\1.txt")

Func _filelist($searchdir,$hzm)
        $search = FileFindFirstFile($searchdir & "\*")
        If $search = -1 Then Return -1
        While 1
                $file = FileFindNextFile($search)
                If @error Then
                        FileClose($search)
                        Return
                ElseIf $file = "." Or $file = ".." Then
                        ContinueLoop
                ElseIf StringInStr(FileGetAttrib($searchdir & "" & $file), "D") Then
                        _filelist($searchdir & "" & $file, $hzm)
                        ContinueLoop
                EndIf
                If StringRight($file, 4) = $hzm Then
                        FileWriteLine($fh, $searchdir & "" & $file)
                EndIf
        WEnd
EndFunc   ;==>_filelist
 楼主| 发表于 2009-8-6 09:29:36 | 显示全部楼层
68# afan


谢谢你的帮助,我大致觉得可以明白和加以修改成自己所需要的。
发表于 2009-8-7 07:49:00 | 显示全部楼层
这些东西是很好玩,只是好多东西我还在学习中,好想能好好运用!
 楼主| 发表于 2009-8-7 17:23:12 | 显示全部楼层
请问afan,

AutoIT里面有没有enable和disable的控制功能啊?就是按了那个按键,某一个功能就可以或者不能使用了。
发表于 2009-8-7 17:42:21 | 显示全部楼层
GUICtrlSetState ( 控件ID, 状态 )
状态:
$GUI_ENABLE 控件将可用.  
$GUI_DISABLE 控件将变成灰色状态(不可用)
发表于 2009-8-7 22:19:06 | 显示全部楼层
....    这个FOR啊,  看的头大了
 楼主| 发表于 2009-8-11 15:25:02 | 显示全部楼层
afan,上次你教了我怎么设定一个限制去读取然后复制制定格式的文件,但是我对于那个Func_filelist看得不是很懂,所以在尝试往自己的程序里面添加的时候失败。

我的程序是还是那个创建文件夹和复制文件的程序,但是我尝试了,在func里面就不能够再加func来运行了,那么怎么把Func_filelist加进去呢?

$Form1 = GUICreate('Multi-Level Folder Creator', 387,265,-1,-1)
Dim $n = 1, $l[15], $s[15]
For $n = 1 To 14
        $l[$n] = GUICtrlCreateLabel("Lv" & $n, 12 + 70 * ($n - (Int(($n - 1) / 5)) * 5 - 1), 20 + 20 * (Int(($n - 1) / 5)), 30, 18)
        $s[$n] = GUICtrlCreateInput("0", 45 + 70 * ($n - (Int(($n - 1) / 5)) * 5 - 1), 17 + 20 * (Int(($n - 1) / 5)), 30, 16, $ES_NUMBER)
        GUICtrlSetLimit(-1, 4)
                Next
$yml = GUICtrlCreateInput("", 11, 85, 240, 23)
$Button = GUICtrlCreateButton("Create Folder / Copy File", 10, 160, 220, 25)
$Button1 = GUICtrlCreateButton("Remove All", 240, 160, 135, 25)
$Button2 = GUICtrlCreateButton("Source File Folder", 255, 84, 120, 26)
$Button3 = HotKeySet("{ESC}", "Terminate")
$gml = GUICtrlCreateInput("",11,120,240,23)
$Button5 = GUICtrlCreateButton("Target Folder", 255, 119, 120, 26)
$xs = GUICtrlCreateLabel("0/0        ", 175, 220, 300, 15)
GUICtrlSetColor(-1, 0xff0000)
$jdt = GUICtrlCreateProgress(10, 200, 365, 12,$PBS_SMOOTH)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        exit

                Case $Button
                        GUICtrlSetData($jdt, 0)
                        GUICtrlSetState($Button, $GUI_ENABLE)
                        Dim $ywc = 0, $zs = 0, $sc = 1,$f,$h
                        jc()
                        AdlibEnable("jdt")
                        If GUICtrlRead($s[1]) = 0 then
                                msgbox(16, 'Error', 'Please set the number of folders')
                                                        Else
                                                                $f=MsgBox(1+48,'Attention','You will create ' & $zs & ' folders.' &@CRLF& 'Do you wish to continue?')
                                                                Select
                                                                        Case $f=1
                                       scml()
                                                                           sleep(300)
                                       AdlibDisable()
                                       msgbox(64, 'Finish', 'Created  ' & $zs & '  Folders! ')
                                                                   Case $f=2
                                                                           ContinueLoop
                                                                   EndSelect  
                                                                                       
                                                                  EndIf
                                                                  GUICtrlSetState($Button,$GUI_ENABLE)
                                                       
                                                Case $Button1
                                        $h=MsgBox(1+48,'Attention','Are you sure you want to Delete all the folders ?')
                                        Select
                                                Case $h=1
                                             Del()
                                             sleep(300)
                                                 msgbox(64, 'Finish', 'You have deleted all the folders! ')
                                            Case $h=2
                                                ContinueLoop
                                                EndSelect
                                Case $Button2
                        $ywjj = FileSelectFolder("Choose The Folder", "", 4)
                        If @error Then ContinueLoop
                        GUICtrlSetData($yml, $ywjj)
                                        Case $Button3
                                        Terminate()
                                Case $Button5
                                        $ywxx = FileSelectFolder("Choose The Folder", "", 4)
                                        If @error Then ContinueLoop
                        GUICtrlSetData($gml, $ywxx)
                                       
        EndSwitch
WEnd

Func Del()
        Dim $num
        For $num = 1 To 1000
        $gmld = GUICtrlRead($gml)       
        DirRemove($gmld & '\' & 'MP3-'&$num,1)
        Next
       
        EndFunc
       
Func jc()
        For $i = 14 To 1 Step -1
                $sl = GUICtrlRead($s[$i])
                If $sl > 0 then
                        For $i1 = 1 To $i
                                $sl1 = GUICtrlRead($s[$i1])
                                If $sl1 = 0 then
                                        GUICtrlSetData($s[$i1], 1)
                                        $sl1 = 1
                                endif
                                $zs = $zs + ($sc * $sl1)
                                $sc = $sc * $sl1
                        Next
                        ExitLoop
                Endif
        Next
EndFunc   ;==>jc

Func Terminate()
   Exit 0
EndFunc
Func scml()
            $ymlr = GUICtrlRead($yml)
                $gmlr = GUICtrlRead($gml)
        $sl1 = GUICtrlRead($s[1])
                If $gmlr = '' Then $gmlr = @ScriptDir
        For $i1 = 1 To $sl1
                $fn1 = 'MP3-'
                $xml1 = $gmlr&'\'&$fn1&$i1
                DirCreate($xml1)
$fh = FileOpen(@ScriptDir & "\1.txt", 1) ;从这里是复制文件的程序
_filelist($$ymlr, '.mp3')
FileClose($fh)

$fh = FileOpen(@ScriptDir & "\1.txt", 0)
While 1
        $rl = FileReadLine($fh)
        If @error = -1 Then ExitLoop
        FileCopy($rl, $gmlr, 9)
WEnd
FileClose($fh)
FileDelete(@ScriptDir & "\1.txt") ; 到这里为止
                $ywc = $ywc + 1
Next
Endfunc   ;==>scml

Func jdt()
        GUICtrlSetData($jdt, $ywc / $zs * 100)
        GUICtrlSetData($xs, $ywc & '/' & $zs)
        EndFunc   ;==>jdt

这里我就弄了一层创建文件夹和复制文件,但是我就不明白在func scml()下面 又怎么可以添加你的Func_filelist进去呢??而且这个复制文件的命令又不能放在前面的while 1 loop里面。我感觉有点乱
 楼主| 发表于 2009-8-11 15:32:29 | 显示全部楼层
程序有点长,其他的都不是很有用,就中间我标明了程序开始和到哪里结束那里请你帮忙看看,谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 12:44 , Processed in 0.075773 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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