将一个文件从一个位置复制到另一个位置的代码如何写
将一个文件从一个位置复制到另一个位置的代码怎么写
比如在同执行程序同目录中有一个 abc.exe ,在执行这个程序时将这个abc.exe复制到系统system32目录中怎么编?
谢谢
------解决方案--------------------
放一个按钮command1
复制以下代码即可
Private Declare Function GetWindowsDirectory Lib "kernel32 " Alias "GetWindowsDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32 " Alias "GetSystemDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As Long
Dim SYSDIR, WINDIR As String
Private Sub Command1_Click()
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR
End Sub
Private Sub Form_Load()
Dim dir As String * 255
Dim a, b As Integer
a = GetSystemDirectory(dir, 255)
dir = Left(dir, a)
a = Len(dir)
b = 1
Do While b <= a
If Mid(dir, b, 1) = " " Then Exit Do
b = b + 1
Loop
SYSDIR = Mid(dir, 1, b - 1) '当前操作系统的Windows系统目录System路径
End Sub
------解决方案--------------------
yurilin(绝对领域) 已经用到FileCopy函数了
稍微改一点点
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR
--》
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR & "\abc.exe "
------解决方案--------------------
用filecopy,应该可以实现。
FileCopy 语句
复制一个文件。
语法
FileCopy source, destination
FileCopy 语句的语法含有以下这些命名参数:
部分 描述
source 必要参数。字符串表达式,用来表示要被复制的文件名。source 可以包含目录或文件夹、以及驱动器。
destination 必要参数。字符串表达式,用来指定要复制的目地文件名。destination 可以包含目录或文件夹、以及驱动器。
说明
如果想要对一个已打开的文件使用 FileCopy 语句,则会产生错误。
比如在同执行程序同目录中有一个 abc.exe ,在执行这个程序时将这个abc.exe复制到系统system32目录中怎么编?
谢谢
------解决方案--------------------
放一个按钮command1
复制以下代码即可
Private Declare Function GetWindowsDirectory Lib "kernel32 " Alias "GetWindowsDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32 " Alias "GetSystemDirectoryA " (ByVal lpbuffer As String, ByVal nSize As Long) As Long
Dim SYSDIR, WINDIR As String
Private Sub Command1_Click()
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR
End Sub
Private Sub Form_Load()
Dim dir As String * 255
Dim a, b As Integer
a = GetSystemDirectory(dir, 255)
dir = Left(dir, a)
a = Len(dir)
b = 1
Do While b <= a
If Mid(dir, b, 1) = " " Then Exit Do
b = b + 1
Loop
SYSDIR = Mid(dir, 1, b - 1) '当前操作系统的Windows系统目录System路径
End Sub
------解决方案--------------------
yurilin(绝对领域) 已经用到FileCopy函数了
稍微改一点点
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR
--》
FileCopy App.Path + "\ " + "abc.exe ", SYSDIR & "\abc.exe "
------解决方案--------------------
用filecopy,应该可以实现。
FileCopy 语句
复制一个文件。
语法
FileCopy source, destination
FileCopy 语句的语法含有以下这些命名参数:
部分 描述
source 必要参数。字符串表达式,用来表示要被复制的文件名。source 可以包含目录或文件夹、以及驱动器。
destination 必要参数。字符串表达式,用来指定要复制的目地文件名。destination 可以包含目录或文件夹、以及驱动器。
说明
如果想要对一个已打开的文件使用 FileCopy 语句,则会产生错误。