|
-
February 10th, 2000, 05:20 PM
#1
How to copy files
How do I copy a file from one directory to another? It seems that the SHELL command only execute ".exe" type of files. Thus, copy does not work for me.
Thanks in advance.
-
February 10th, 2000, 05:55 PM
#2
Re: How to copy files
Use the VB FileSystemObject method CopyFile
Dim fso as New FileSystemObject (note that the Microsoft Scripting Runtime library must be referenced in your project)
fso.CopyFile "from path" "to path"
hope that helps
PSH
-
February 10th, 2000, 05:56 PM
#3
Re: How to copy files
There are a couple of ways to do this:
1)
Sub CopyFiles(SourceFile as string, TargetFile as string)
FileCopy SourceFile, TargetFile
End Sub
That will work in native VB without setting any references. SourceFile and Target must be full paths to the file.
2) Set a reference to the Microsoft Scripting Runtime
Sub CopyFiles(SourceFile as string, TargetFile as string)
Dim FSO as Scripting.FileSystemObject
set FSO = new Scripting.FileSystemObject
'CopyFile (Source, Target, Overwrite Existing as Boolean)
FSO.CopyFile SourceFile, TargetFile, true
set FSO = nothing
End Sub
I like the second way better because I can specify if I want the file overwritten if it already exists, you don't have that option in the first way.
Hope this helps,
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|