;
帖子
3919 
精华
积分
11710 
鱼币
0 ¥ 
来自
大连 
在线时间
1858 小时 
注册时间
2007-6-11 
最后登录
2009-10-20 

贴图大师勋章新人进步勋章宣传大使勋章论坛元老勋章

3
发表于 2009-1-5 19:48 | 只看该作者
濡備綍鐢ㄧ▼搴忔潵Delete Copy Move Rename File/Directory - 缂栫▼搴 - Powered by SupeSite

浣犵殑浣嶇疆锛缂栫▼搴 >> 璧勮 >> VB >> 鏂囦欢鎿嶄綔 >> 璇︾粏鍐呭 鍦ㄧ嚎鎶曠ǹ

濡備綍鐢ㄧ▼搴忔潵Delete Copy Move Rename File/Directory

鍙戝竷: 2008-6-26 09:30 |  浣滆: admin |   鏌ョ湅: 17娆

鍘熷鏉ユ簮:鐜嬪浗鑽 cww 鏇存敼

Private Type SHFILEOPSTRUCT

hwnd As Long

wFunc As Long

pFrom As String

pTo As String

fFlags As Integer

fAnyOperationsAborted As Long

hNameMappings As Long

lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Type

'wFunc 鐨勮瀹氬

'FO_COPY Copies the files specified by pFrom to the location specified by pTo.

'FO_DELETE Deletes the files specified by pFrom (pTo is ignored).

'FO_MOVE Moves the files specified by pFrom to the location specified by pTo.

'FO_RENAME Renames the files specified by pFrom.

'fFlag鐨勮瀹

'FOF_ALLOWUNDO Preserves undo information, if possible.

'FOF_FILESONLY Performs the operation only on files if a wildcard filename

' (*.*) is specified.

'FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple destination

' files (one for each source file) rather than one directory where

' all source files are to be deposited.

'FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is displayed.

'FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if

' the operation requires one to be created.

'FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such as

' "Copy #1 of...") in a move, copy, or rename operation

' if a file of the target name already exists.

'FOF_SILENT Does not display a progress dialog box.

'FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the

' filenames.

'FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must be

' freed by using the SHFreeNameMappings function.

Const FO_MOVE = &H1

Const FO_COPY = &H2

Const FO_DELETE = &H3

Const FOF_NOCONFIRMATION = &H10

Const FOF_NOCONFIRMMKDIR = &H200

Const FOF_ALLOWUNDO = &H40

Const FOF_SILENT = &H4

Private Declare Function SHFileOperation Lib "shell32.dll" Alias _

"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

'鍒犻櫎 test鐩綍鍙婂叾搴曚笅鐨勫瓙鐩綍鍒拌祫婧愬洖鏀舵《

Private Sub Command1_Click()

Dim SHFileOp As SHFILEOPSTRUCT

SHFileOp.wFunc = FO_DELETE

SHFileOp.pFrom = "c:\test" + Chr(0)

'涓嶅嚭鐜版。妗堝垹闄ょ殑鍔ㄦ丄VI锛屼笖涓岰onfirm

SHFileOp.fFlags = FOF_SILENT + FOF_ALLOWUNDO + FOF_NOCONFIRMATION

'鑻ユ病鏈 FOF_ALLOWUNDO 鍒欎笉浼氬埌璧勬簮鍥炴敹妗

Call SHFileOperation(SHFileOp)

End Sub

'鍚屾椂鍒犻櫎澶氭。鍒拌祫婧愬洖鏀舵《

Private Sub Command2_Click()

Dim SHFileOp As SHFILEOPSTRUCT

Dim Files As String

'Files = "c:\test.txt" + Chr(0)

Files = "c:\test1.txt" + Chr(0) + "c:\test2.txt" + Chr(0) + _

"c:\test3.txt" + Chr(0)

SHFileOp.wFunc = FO_DELETE

SHFileOp.pFrom = Files

'鍒犺嚦璧勬簮鍥炴敹妗讹紝涓斾笉Confirm

SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION

Call SHFileOperation(SHFileOp)

End Sub

'灏 c:\temp 鏁翠釜鐩綍澶嶅埗鍒 c:\temp2

Private Sub Command3_Click()

Dim SHFileOp As SHFILEOPSTRUCT

SHFileOp.wFunc = FO_COPY

SHFileOp.pFrom = "c:\temp\*.*"

SHFileOp.pTo = "c:\temp2\*.*"

SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR

Call SHFileOperation(SHFileOp)

End Sub

'灏 c:\test4.txt 蹇熺Щ鍒 c:\temp 鐩綍

Private Sub Command4_Click()

Dim SHFileOp As SHFILEOPSTRUCT

SHFileOp.wFunc = FO_MOVE

SHFileOp.pFrom = "c:\test4.txt" + Chr(0)

SHFileOp.pTo = "c:\temp"

SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION

Call SHFileOperation(SHFileOp)

End Sub

鎵撳嵃 | 鏀惰棌姝ら〉 |  鎺ㄨ崘缁欏ソ鍙 | 涓炬姤
涓婁竴绡 涓嬩竴绡
 

璇勫垎锛0

鍙戣〃璇勮
鏌ョ湅鍏ㄩ儴鍥炲銆愬凡鏈0浣嶇綉鍙嬪彂琛ㄤ簡鐪嬫硶銆