Set fso1 = CreateObject("Scripting.FileSystemObject") Set fdir1 = fso1.GetFolder("d:\zb\jwa\") Set f1 = fdir1.Files
For Each f In f1 fso1.copyfile f, "c:\" & yourname here, True Next
Dim Fs As Variant Set Fs = CreateObject("Scripting.FileSystemObject") If Fs.FolderExists("c:\ff\") Then Fs.CopyFile "c:\*.txt", "c:\ff\" Fs.CopyFile "c:\i.txt", "c:\ff\uu.txt" End If 不就行了,多看看filesystemobject吧
声明: Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long 使用: CopyFile "c:\aa.txt","d:\bb.txt",False (如后面的设为true,如存在同名文件,会出错,如上设为False,则覆盖)
1;用 API 函数 Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long 2:用 CopyFile 语句 filecoy 原文件名 ,目标文件名
改名
Name yyy As xxx
Set fdir1 = fso1.GetFolder("d:\zb\jwa\")
Set f1 = fdir1.Files
For Each f In f1
fso1.copyfile f, "c:\" & yourname here, True
Next
Set Fs = CreateObject("Scripting.FileSystemObject")
If Fs.FolderExists("c:\ff\") Then
Fs.CopyFile "c:\*.txt", "c:\ff\"
Fs.CopyFile "c:\i.txt", "c:\ff\uu.txt"
End If
不就行了,多看看filesystemobject吧
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
使用:
CopyFile "c:\aa.txt","d:\bb.txt",False
(如后面的设为true,如存在同名文件,会出错,如上设为False,则覆盖)
复制一个文件。语法FileCopy source, destinationFileCopy 语句的语法含有以下这些命名参数:部分 描述
source 必要参数。字符串表达式,用来表示要被复制的文件名。source 可以包含目录或文件夹、以及驱动器。 destination 必要参数。字符串表达式,用来指定要复制的目地文件名。destination 可以包含目录或文件夹、以及驱动器。
说明如果想要对一个已打开的文件使用 FileCopy 语句,则会产生错误FileCopy 语句示例
本示例使用 FileCopy 语句来复制文件。示例中假设 SRCFILE 为含有数据的文件。Dim SourceFile, DestinationFile
SourceFile = "SRCFILE" ' 指定源文件名。
DestinationFile = "DESTFILE" ' 指定目的文件名。
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。
录入 filecopy c:\test.txt,c:\mydocument\test1.txt
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
2:用 CopyFile 语句
filecoy 原文件名 ,目标文件名