关于FileCopy出错,请大家给帮助。谢谢!

mmy628 2005-09-10 09:37:48
我写了一个保存文件的方法:
filecopy "d:\vbtest\access01.mdb","d:\vbback\access02.mdb"
运行时报错,说我没有权限?要不就是路径出错。
请问这是什么原因,如果要用相对路径又怎样才能写呢?谢谢!
...全文
134 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmy628 2005-09-16
  • 打赏
  • 举报
回复
我为什么给不出去分呢?说我的“分总和不对,请验证?”想送分给帮助过我的朋友都有这么难吗?
xiaoyaolz 2005-09-13
  • 打赏
  • 举报
回复
'逍遥浪子编程
'网志:http://blog.csdn.net/xiaoyaolz
'交个朋友,一起编程,学习,一生的朋友
'######################################## dofile,start ############################################
'[简介]:
'改名,移动,拷贝
'[函数说明]:
'限于窗体运行
'[参数说明]:
'.wfunc=fo_rename(改名) fo_move(移动) fo_copy(拷贝)
Function dofile(DOMODE,FILE1,FILE2) As boolean
'[mycode_id:119],edittime:2005-2-14 19:20:46
'[codejs_s:模块声明]
'在标准模块中添加以下代码:
Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Type SHFILEOPSTRUCT
hwnd As Long '窗口句柄
wFunc As Long '执行的操作
pFrom As String '原地点
pTo As String '目标地点
fFlags As Long '操作执行方式
fAnyOperationsAborted As Long '错误代码返回
hNameMappings As Long
lpszProgressTitle As String
End Type

Public Const FO_MOVE As Long = &H1
Public Const FO_COPY As Long = &H2
Public Const FO_DELETE As Long = &H3
Public Const FO_RENAME As Long = &H4

Public Const FOF_MULTIDESTFILES As Long = &H1
Public Const FOF_CONFIRMMOUSE As Long = &H2
Public Const FOF_SILENT As Long = &H4
Public Const FOF_RENAMEONCOLLISION As Long = &H8
Public Const FOF_NOCONFIRMATION As Long = &H10
Public Const FOF_WANTMAPPINGHANDLE As Long = &H20
Public Const FOF_CREATEPROGRESSDLG As Long = &H0
Public Const FOF_ALLOWUNDO As Long = &H40
Public Const FOF_FILESONLY As Long = &H80
Public Const FOF_SIMPLEPROGRESS As Long = &H100
Public Const FOF_NOCONFIRMMKDIR As Long = &H200
'[codejs_e:模块声明]
Dim DelFileOp As SHFILEOPSTRUCT
Dim result As Long
With DelFileOp
.hwnd = Me.hwnd
.wFunc = DOMODE '(删除)
'.wfunc=fo_rename(改名) fo_move(移动) fo_copy(拷贝)
' Delete the files you just moved to C:\TestFolder.
' If you do not have these files, you can alter this
' sample to point to existing files.
' .pFrom = "C:\testfolder\file1" & vbNullChar & "c:\testfolder\file2" & vbNullChar & vbNullChar
.pFrom = file1 & vbNullChar & vbNullChar
'"d:\testfolder\*" & vbNullChar & vbNullChar
if domode<>FO_DELETE THEN
'.pTo = "d:\test" (移动,拷贝时有效)
.pTo =file2
END IF
' Allow undo--in other words, place the files into the Recycle Bin
.fFlags = FOF_ALLOWUNDO
End With
result = SHFileOperation(DelFileOp)
If result <> 0 Then ' Operation failed
If Err.LastDllError <> 0 Then
MsgBox Err.LastDllError ' Msgbox the error that occurred in the API.
End If
Else
If DelFileOp.fAnyOperationsAborted <> 0 Then
MsgBox "Operation Failed"
End If
End If
End Function
'######################################## dofile,end ############################################
cly2004 2005-09-11
  • 打赏
  • 举报
回复
文件不存在是由于:"d:\vbtest\access01.mdb" ' 指定源文件名。不存在啦

没有权限或路径出错
d:\vbback\access02.mdb ' 指定目的文件名。已经存在并且为只读时,如果有盖掉它就会这样报错啦

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧