用VB复制当前目录子文件夹下面的文件到当前文件夹下
展开全部
Option Explicit
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
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
End Type
Const FO_COPY = &H2
Const FOF_ALLOWUNDO = &H40
Const FOF_NOCONFIRMMKDIR = &H200
Private Sub Command1_Click()
Dim FilePath As String
FilePath = App.Path & "\123\test.txt"
If Dir(FilePath) = "" Then
MsgBox "文件不存在"
Else
Dim SHFileOp As SHFILEOPSTRUCT
SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = FilePath
SHFileOp.pTo = App.Path
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp)
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim fso as new scripting.filesystemobject
fso.copyfile app.path & "\123\test.txt",app.path & "\tset.txt"
fso.copyfile app.path & "\123\test.txt",app.path & "\tset.txt"
追问
我用的是一个按钮 Command1,提示过程声明与同名事件或过程的描述不匹配,应该怎么声明?
Private Sub Command1_Click(????)
dim fso as new scripting.filesystemobject
fso.copyfile filename,filename
End Sub
要是能加个检测文件是否存在更好了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询