找回密码
 加入
搜索
查看: 4294|回复: 2

[AU3基础] 函数怎么才能重复调用???

[复制链接]
发表于 2014-11-22 16:02:38 | 显示全部楼层 |阅读模式
在论坛找到下面的  ProgressCopy 带进度copy的函数,可以正常使用。但是不能重复调用
如:
ProgressCopy("H:\QQ三国", "D:\新建文件夹\",1);;执行完毕后,我想再次copy 其他文件夹就不可以。 该如何写 ?谢谢了
ProgressCopy("H:\QQ", "D:\QQ\",1);
#include <GUIConstants.au3> 
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
 
ProgressCopy("H:\QQ三国", "D:\新建文件夹",1);要复制的文件 
Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )
 
;FirstTimeRun Get original DirSize and set up Gui 
If $Run1 = 0 Then 
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent 
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0) 
If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist 
$source = $current 
If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1) 
If StringRight($destination, 1) <> '\' Then $destination = $destination & "" 
$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) 
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
发表于 2014-11-22 18:07:54 | 显示全部楼层
回复 1# laomeng


   本来已经是"封装"好的UDF,当然想什么时候用就什么时候用!
关键是你根本不知道怎么做,基础简直都没有,要努力啊.

给你点代码.如果还不知道怎么做,我也无能为力了.
HotKeySet('{esc}', '_exit') ;按 esc 键退出程序
HotKeySet('!r', '_r_copy') ; 按 alt+r 键开始复制

While 1
        Sleep(100)
WEnd

Func _exit()
        If MsgBox(1+32, '退出提醒', '确认要退出?', 5) = 1 Then Exit
EndFunc

Func _r_copy()
        Local $sPath_s = FileSelectFolder('选择要复制的文件夹', '')
        If @error Then Return
        Local $sPath_d = FileSelectFolder('选择目的文件夹,可新建', '', 1)
        If @error Then Return
        ProgressCopy($sPath_s, $sPath_d, 1)
EndFunc
 楼主| 发表于 2014-11-22 19:49:13 | 显示全部楼层
回复 2# user3000

是还得多学习学习 !

    哦 那可能是我写错, 我直接在 case 下 这样写的 ;   但只执行第一条

ProgressCopy($sPath_s, $sPath_d, 1)
ProgressCopy($sPath_1s, $sPath_1d, 1)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-15 01:32 , Processed in 0.071990 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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