AU3复制或移动文件显示进度条的方法
<P>Option Explicit </P><P>Private Type SHFILEOPSTRUCT <BR> hWnd As Long <BR> wFunc As Long <BR> pFrom As String <BR> pTo As String <BR> fFlags As Integer <BR> fAnyOperationsAborted As Long <BR> hNameMappings As Long <BR> lpszProgressTitle As String <BR>End Type </P>
<P>Private Declare Function SHFileOperation Lib "shell32.dll" _ <BR> Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long </P>
<P>Private Const FOF_ALLOWUNDO = &H40 <BR>Private Const FOF_NOCONFIRMATION = &H10 <BR>Private Const FOF_SIMPLEPROGRESS = &H100 </P>
<P>Private Const FO_COPY = &H2 <BR>Private Const FO_MOVE = &H1 </P>
<P>'-------------------------------------------------------------------------------- <BR>' 过程: ShellFileCopy <BR>' 描述: 复制文件,并显示“正在复制...”进度条对话框 <BR>' 返回: True为复制成功,False为复制失败 <BR>' <BR>' 参数: <BR>' Src (String) 要复制的源文件 <BR>' Dest (String) 要复制到的位置 <BR>' hWnd (Long) 父窗体的句柄(可选) <BR>' NoShowText (Boolean = False) 是否不显示复制的文件名 <BR>' NoConfirm (Boolean = False) 是否不显示确认对话框 <BR>' <BR>'-------------------------------------------------------------------------------- <BR>Public Function ShellFileCopy(Src As String, Dest As String, _ <BR> Optional hWnd As Long, _ <BR> Optional NoShowText As Boolean = False, _ <BR> Optional NoConfirm As Boolean = False) As Boolean </P>
<P> Dim SFO As SHFILEOPSTRUCT <BR> Dim lRet As Long <BR> Dim lflags As Long </P>
<P> lflags = FOF_ALLOWUNDO </P>
<P> If NoShowText Then lflags = lflags Or FOF_SIMPLEPROGRESS </P>
<P> If NoConfirm Then lflags = lflags Or FOF_NOCONFIRMATION </P>
<P> With SFO </P>
<P> .wFunc = FO_COPY <BR> .pFrom = Src <BR> .pTo = Dest <BR> .fFlags = lflags <BR> <BR> End With </P>
<P> lRet = SHFileOperation(SFO) <BR> ShellFileCopy = (lRet = 0) </P>
<P>End Function </P>
<P>'-------------------------------------------------------------------------------- <BR>' 过程: ShellFileMove <BR>' 描述: 移动文件,并显示“正在移动...”进度条对话框 <BR>' 返回: True为移动成功,False为移动失败 <BR>' <BR>' 参数: <BR>' Src (String) 要移动的源文件 <BR>' Dest (String) 要移动到的位置 <BR>' hWnd (Long) 父窗体的句柄(可选) <BR>' NoShowText (Boolean = False) 是否不显示移动的文件名 <BR>' NoConfirm (Boolean = False) 是否不显示确认对话框 <BR>' <BR>'-------------------------------------------------------------------------------- <BR>Public Function ShellFileMove(Src As String, Dest As String, _ <BR> Optional hWnd As Long, _ <BR> Optional NoShowText As Boolean = False, _ <BR> Optional NoConfirm As Boolean = False) As Boolean </P>
<P> Dim SFO As SHFILEOPSTRUCT <BR> Dim lRet As Long <BR> Dim lflags As Long </P>
<P> lflags = FOF_ALLOWUNDO </P>
<P> If NoShowText Then lflags = lflags Or FOF_SIMPLEPROGRESS </P>
<P> If NoConfirm Then lflags = lflags Or FOF_NOCONFIRMATION </P>
<P> With SFO </P>
<P> .wFunc = FO_MOVE <BR> .pFrom = Src <BR> .pTo = Dest <BR> .fFlags = lflags <BR> <BR> End With </P>
<P> lRet = SHFileOperation(SFO) <BR> ShellFileMove = (lRet = 0) </P>
<P>End Function <BR></P>
<P> </P>
经朋友介绍,日前获得了一段VB的源代码,用于复制或移动文件显示进度条,哪位高人可以把这个改成AU3的不,感激不尽!!
[ 本帖最后由 skyfree 于 2008-7-29 15:14 编辑 ] API的话。工程实太大了。不过API有返回值判断,就是非常麻烦。将就一下,用SHELL对象来实现,简单化^_^
;_DirCopy('d:\sf','d:\aaa')
;_DirMove("d:\abc","e:\ooq")
Func _DirCopy($SourceDir,$Destdir)
;说明:利用Shell对象来实现复制文件对话框
;作者:Sanhen
Local $Shell
Local $FOF_SIMPLEPROGRESS = 16
If Not FileExists($Destdir) Then DirCreate($Destdir)
$Shell = ObjCreate("shell.application")
$Shell.namespace($Destdir).CopyHere($SourceDir,$FOF_SIMPLEPROGRESS)
EndFunc
Func _DirMove($SourceDir,$Destdir)
;说明:利用Shell对象来实现移动文件对话框
;作者:Sanhen
Local $Shell
Local $FOF_CREATEPROGRESSDLG = 16
If Not FileExists($Destdir) Then DirCreate($Destdir)
$Shell = ObjCreate("Shell.Application")
$Shell.NameSpace($Destdir).MoveHere($SourceDir, $FOF_CREATEPROGRESSDLG)
EndFunc
还是sanhen厉害!方法不错,简单实用。
我这里有我论坛7猫给我的一段用于复制文件显示进度条的AU3代码,共同交流吧
Global Const $FO_COPY = 0x0002
Global Const $FOF_ALLOWUNDO = 0x0040
_ExplorerCopy("f:\XPBAK.gho", "D:\")
Func _ExplorerCopy($source, $dest)
Local $SHFILEOPSTRUCT, $source_struct, $dest_struct
$SHFILEOPSTRUCT = DllStructCreate("hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;" & _
"int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle")
$source_struct = DllStructCreate("char[" & StringLen($source) + 2 & "]")
DllStructSetData($source_struct, 1, $source)
DllStructSetData($source_struct, 1, 0, StringLen($source) + 2)
$dest_struct = DllStructCreate("char[" & StringLen($dest) + 2 & "]")
DllStructSetData($dest_struct, 1, $dest)
DllStructSetData($dest_struct, 1, 0, StringLen($dest) + 2)
DllStructSetData($SHFILEOPSTRUCT, "hWnd", 0)
DllStructSetData($SHFILEOPSTRUCT, "wFunc", $FO_COPY)
DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($source_struct))
DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($dest_struct))
DllStructSetData($SHFILEOPSTRUCT, "fFlags", $FOF_ALLOWUNDO)
DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT))
EndFunc ;==>_ExplorerCopy
[ 本帖最后由 skyfree 于 2008-7-29 15:03 编辑 ] 比较好收藏一下.....
[ 本帖最后由 jinghai 于 2008-7-29 16:27 编辑 ] 留个脚印 学习下 太深奥.做个记号 标记一下吧 还是很实用的说 这个确实很实用的 回复 3# skyfree
怎么实现自动复制替换已存在的文件?? 回复 2# sanhen
看您用shell用的好帅 , 您是怎么学的?
能够在copy的时候加上进度条吗? 学习一下! 过来学习 学习 回复sanhen
看您用shell用的好帅 , 您是怎么学的?
能够在copy的时候加上进度条吗?
yarsye 发表于 2011-1-10 17:38 http://www.autoitx.com/images/common/back.gif
复制的时候本来就显示了进度条你没测试过么 老大的帖子怎么也得顶一下 {:face (125):}这个确实好用,谢谢拉。
页:
[1]
2