vb中复制文件

vb中复制文件,第1张

用API函数 SHFileOperation的方法。

以下是使用SHFileOperation删旦凯除复制移动文件的例子,可以复制文件夹

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 '只有在 FOF_SIMPLEPROGRESS 时用

End Type

Private Declare Function SHFileOperation Lib _

"shell32.dll" Alias "SHFileOperationA" (lpFileOp _

As SHFILEOPSTRUCT) As Long

'wFunc 常数

'FO_COPY 把 pFrom 文件拷贝到 pTo。

Const FO_COPY = &H2

'FO_DELETE 删除 pFrom 中的文件(pTo 忽略)。

Const FO_DELETE = &H3

'FO_MOVE 把 pFrom 文件移动到 pTo。

Const FO_MOVE = &H1

'fFlag 常脊迟键数

'FOF_ALLOWUNDO 允许 Undo 。

Const FOF_ALLOWUNDO = &H40

'FOF_NOCONFIRMATION 不显示系统确认对话框。

Const FOF_NOCONFIRMATION = &H10

'FOF_NOCONFIRMMKDIR 不提示樱巧是否新建目录。

Const FOF_NOCONFIRMMKDIR = &H200

'FOF_SILENT 不显示进度对话框

Const FOF_SILENT = &H4

Private Sub Command1_Click()

'例子:

Dim SHFileOp As SHFILEOPSTRUCT

' 拷贝

SHFileOp.wFunc = FO_COPY

SHFileOp.pFrom = "d:\MASM611"

SHFileOp.pTo = "c:\MASM611"

SHFileOp.fFlags = FOF_NOCONFIRMMKDIR

Call SHFileOperation(SHFileOp)

End Sub

或者用命令行

shell "cmd.exe /c xcopy "+chr(34)+"C:\新建文件夹 c:\aa /q /e" +chr(34)

1.VB自己的命令 filecopy text1.text,text2.text 2.VBS的命橘乱肢令 Set fso = CreateObject("Scripting.FileSystemObject") fso.copy text1.text,text2.text 全部删除复制 移动的如下: dim a,b,c On Error Resume Next c=inputbox("请输入 *** 作代码:1.删除;2.复制,陪埋3.移动","6921833","D:") a=inputbox("请输入源文件的目录","6921833","D:") if c<>圆世1 then b=inputbox("请输目标文件夹","6921833","D:") else b=0 end if Tree(a,b,c) Set WshSHell = WScript.CreateObject("WScript.Shell") msgbox"OK" Function Tree(sPath,spath2,whatdo) On Error Resume Next Dim WshSHell,oFso Set oFso = CreateObject("Scripting.FileSystemObject") Set oFolder = oFso.GetFolder(sPath) Set oSubFolders = oFolder.Subfolders Set oFiles = oFolder.Files For Each oFile In oFiles '文件 if whatdo=1 then oFile.delete elseif whatdo=2 then oFile.Copy (spath2) elseif whatdo=3 oFile.Movw (spath2) end if Next For Each oSubFolder In oSubFolders TreeIt(oSubFolder.Path)'递归 Next Set objFolder=oFso.Getfolder(a) Set subFolders=objFolder.subFolders For Each subFolder In subFolders On Error Resume Next if whatdo=1 then subfolder.Delete(True) If Err Then err.Clear Else End If Next Set oFolder = Nothing Set oSubFolders = Nothing Set oFso = Nothing End Function


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12226903.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存