Click to See Complete Forum and Search --> : Copying a file.


ansi
August 12th, 2001, 02:10 PM
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!

John G Duffy
August 12th, 2001, 07:10 PM
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

Iouri
August 13th, 2001, 07:02 AM
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
iouri@hotsheet.com