7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, ByVal lpSecurityAttributes As Long) As Long
Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Const GENERIC_ALL = &H10000000
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Sub main()
Dim hFile As Long
'创建文件夹
CreateDirectory "c:\lyserver", 0
'创建文件
hFile = CreateFile("c:\lyserver\temp.old", GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
CloseHandle hFile
'复制文件
CopyFile "c:\lyserver\temp.old", "c:\lyserver\temp.bak", 0
'重命名文件
MoveFile "c:\lyserver\temp.old", "c:\lyserver\temp.new"
'移动文件
MoveFile "c:\lyserver\temp.new", "c:\temp.new"
End Sub