Can anyone tell me how to copy a file in visual basic. I want a file to be copied from a base directory to another directory, and the filename can be renamed. Can somone tell me how to do this or just how to copy it to another directory? :) Thanks!
Printable View
Can anyone tell me how to copy a file in visual basic. I want a file to be copied from a base directory to another directory, and the filename can be renamed. Can somone tell me how to do this or just how to copy it to another directory? :) Thanks!
From the Help Facility
'
'
Visual Basic for Applications Reference
'
FileCopy Statement
'
'
Copies a file.
'
Syntax
'
FileCopy source, destination
'
The FileCopy statement syntax has these named arguments:
'
Part Description
'
source Required.
'
String expression that specifies the name of the file to be copied. The source may include directory or folder, and drive.
'
destination Required.
'
String expression that specifies the target file name. The destination may include directory or folder, and drive.
'
'
Remarks
'
If you try to use the FileCopy statement on a currently open file, an error occurs.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
John G
Here are several examples how to copy a file
1.faster than FileCopy
'ref to MS scripting runtime
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\openfile.txt", "C:\newfile.txt"
2.only for closed file
FileCopy "C:\OpenFile.txt", "C:\NewFile.txt"
3.
shell "start.exe type c:\finename.txt >> hjjkhkj"
Iouri Boutchkine
[email protected]