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

请教下afan。。。关于ProgressCopy

[复制链接]
发表于 2009-9-30 19:01:16 | 显示全部楼层 |阅读模式
http://www.autoitx.com/forum.php ... id=7644076#pid93521

这样改后无法ProgressCopy("D:\", "E:\temp", 1, '', '', '', 1),直接autoit错误
发表于 2009-9-30 19:16:40 | 显示全部楼层
本帖最后由 afan 于 2009-9-30 19:42 编辑

的确没考虑到全盘复制,把那段稍改一下
;;;;------------------以下这段为新增部分
If $AddDir = 1 Then
        If StringInStr($current, '\') <> 0 Then 
                $szwjj = StringRegExp($current, '\\([^\\]+)$', 3)
        Else
                $szwjj = StringRegExp($current, '([^:]+):?', 3)
        EndIf
        $destination = $destination & $szwjj[0] & ""
EndIf
;;;;------------------新增结束
 楼主| 发表于 2009-9-30 20:33:29 | 显示全部楼层
我是用 If $Ddir = "" Then $destination = $destination & $Ddir[0] & "\";;;;;
发表于 2009-9-30 20:39:48 | 显示全部楼层
完整代码也贴上好了
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>

;ProgressCopy("D:\autoit3", "E:\temp", 1) ;不添加源文件夹例子
ProgressCopy("D:\autoit3", "E:\temp", 1, '', '', '', 1) ;添加源文件夹例子

Func ProgressCopy($current, $destination, $UseMultiColour = 0, $attrib = "-R", $overwrite = 1, $Run1 = 0, $AddDir = 0) ;;;;修改增加$AddDir参数,默认0为不添加源文件夹
        ;FirstTimeRun Get original DirSize and set up Gui
        If $Run1 = 0 Then
                Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent, $szwjj
                DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
                $source = $current
                If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
                If StringRight($destination, 1) <> '\' Then $destination = $destination & ""
                ;;;;------------------以下这段为新增部分
                If $AddDir = 1 Then
                        If StringInStr($current, '\') <> 0 Then 
                                $szwjj = StringRegExp($current, '\\([^\\]+)$', 3) 
                        Else
                                $szwjj = StringRegExp($current, '([^:]+):?', 3) 
                        EndIf
                        $destination = $destination & $szwjj[0] & ""
                EndIf
                ;;;;------------------新增结束
                If Not FileExists($destination) Then DirCreate($destination); This is why it was failing, the dir did not exist;;;;变更此行代码位置
                $tosearch = $current
                $Overall = DirGetSize($tosearch, 1)
                $OverallQty = $Overall[1] 
                Global Const $PrCopyGui = GUICreate("进度条", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
                $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
                $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
                GUICtrlSetColor(-1, 32250)
                $Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
                $progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
                $Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
                GUISetFont(10, 600)
                ;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)
                GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
                GUISetState(@SW_SHOW)
                GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
                $Run1 = 1
        EndIf
        $Size = DirGetSize($current, 3) 
        $Qty = $Size[1] 
        Local $search = FileFindFirstFile($current & "\*.*") 
        While 1
                Dim $file = FileFindNextFile($search)
                If @error Or StringLen($file) < 1 Then ExitLoop
                If Not StringInStr(FileGetAttrib($current & "" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        $Qty -= 1
                        $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
                        $OverallQty -= 1
                        $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
                        GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
                        GUICtrlSetData($progressbar1, $overallpercent)
                        GUICtrlSetData($progressbar2, $LocalPercent)
                        GUICtrlSetData($Progress2Text, "Copying File " & $file)
                        If $UseMultiColour Then
                                GUICtrlSetColor($progressbar2, _ChangeColour($LocalPercent))
                                GUICtrlSetColor($progressbar1, _ChangeColour($overallpercent))
                        EndIf
                        FileCopy($current & "" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "" & $file, $overwrite)
                        FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "" & $file, $attrib) 
                EndIf
                If StringInStr(FileGetAttrib($current & "" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "" & $file)
                        FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "" & $file, $attrib)
                        GUICtrlSetData($Progress1Text, $current & "" & $file)
                        ProgressCopy($current & "" & $file, $destination, $UseMultiColour, $attrib, $overwrite, 1, $AddDir) ;;;;修改增加$AddDir参数
                EndIf
        WEnd
        FileClose($search)
        ;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
        If $overallpercent = 100 Then
                GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
                GUICtrlSetData($progressbar1, 100)
                GUICtrlSetData($progressbar2, 100)
                GUICtrlSetData($Progress2Text, "Done!")
                Sleep(2000)
                GUIDelete($PrCopyGui)
                $Run1 = 0
        EndIf
EndFunc   ;==>ProgressCopy

Func _ChangeColour($start)
        $Redness = Int(255 - ($start / 100 * 512))
        If $Redness < 0 Then $Redness = 0
        $Greeness = Int(($start / 100 * 512) - 257)
        If $Greeness < 0 Then $Greeness = 0
        $Blueness = Int(255 - ($Redness + $Greeness))
        Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
EndFunc   ;==>_ChangeColour
 楼主| 发表于 2009-9-30 20:42:51 | 显示全部楼层
StringRegExp($current, '([^:]+):?', 3)
学习了
发表于 2009-9-30 20:44:33 | 显示全部楼层
以上改了之后盘符视为一个文件夹,如
ProgressCopy("D:\", "E:\temp", 1, '', '', '', 1)
的结果为复制到 E:\temp\D\
 楼主| 发表于 2009-9-30 20:57:07 | 显示全部楼层
恩,我知道,所以我没用这个源码,因为若是是disk的话,就不创建文件夹了。。。
                If $AddDir = 1 Then ;;;;
                        If StringInStr($current, '\') <> 0 Then ;;;;判断源目录是否为相对路径
                                $Ddir = StringRegExp($current, '\\([^\\]+)$', 3) ;;;;
                        Else;;;;
                                $Ddir = StringRegExp($current, '.+', 3) ;;;;([^:]+):?
                        EndIf;;;;
                         If $Ddir = "" Then $destination = $destination & $Ddir[0] & "\";;;;;
        EndIf;;;;
 楼主| 发表于 2009-9-30 20:58:17 | 显示全部楼层
不过,也可以搞作msgbox给用户判断
发表于 2009-9-30 21:06:31 | 显示全部楼层
哦,你是这个意思,那直接 ProgressCopy("D:\", "E:\temp", 1) 不就行了吗~ (默认就是不创建文件夹)
 楼主| 发表于 2009-9-30 21:07:38 | 显示全部楼层
额,可是,我修改后,必须是$AddDir = 1,不能为0,因为不想让用户判断
发表于 2009-9-30 21:12:58 | 显示全部楼层
哦,是这样~
那就加个选框吧,让用户决定
 楼主| 发表于 2009-9-30 21:15:03 | 显示全部楼层
曾经想过,但要加的话,版面就难看了,所以没搞
发表于 2009-9-30 21:20:22 | 显示全部楼层
不知道你的软件功能,如果是批量任务那还是使用选框好,不会次次询问,如果是单个任务就无所谓了
 楼主| 发表于 2009-9-30 22:12:16 | 显示全部楼层
当然是单个任务。。。多任务的暂时不想搞
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 06:42 , Processed in 0.077282 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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