?
Solved

how to copy a file from a given location to another

Posted on 2003-04-01
6
Medium Priority
?
127 Views
Last Modified: 2010-05-01
hi,
Can u tell mehow to copy a file from a given location to another in vb.I tried FileCopy method it gave an error.
Ananthan
0
Comment
Question by:rtananthan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 120 total points
ID: 8244098
Did you try it correctly, because it has to work...

FileCopy "c:\filename.ext", "a:\filename.ext"
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8244119
Try this:

Private Declare Function URLDownloadToFile Lib "urlmon" _
                     Alias "URLDownloadToFileA" _
                    (ByVal pCaller As Long, _
                     ByVal szURL As String, _
                     ByVal szFilename As String, _
                     ByVal dwReserved As Long, _
                     ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Private Const ERROR_SUCCESS As Long = 0


Private Function DownloadFile(ByVal sURL As String, _
                             ByVal sLocalFile As String) As Boolean

   Dim lngRetVal As Long
   
  'if the API returns ERROR_SUCCESS (0),
  'return True from the function
   DownloadFile = URLDownloadToFile(0&, _
                                    sURL, _
                                    sLocalFile, _
                                    0&, _
                                    0&) = ERROR_SUCCESS
   
End Function

Private Function DeleteCache(sURL As String) As Boolean
    DeleteCache = DeleteUrlCacheEntry(sURL)
End Function

Use like:

DownloadFile sourcepath, targetpath

Add DeleteCache sourcepath before the line if you want to download an internet file.

Hope this helps
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 8244169
What is your exact statement and what was the error?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:emadat
ID: 8246390
Try this:
Shell "cmd /C copy file1_path_name file2_path_name"

This will simply let the OS do the copy for you
0
 

Expert Comment

by:CleanupPing
ID: 8531215
Hi rtananthan,
This old question (QID 20569782) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9017774
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept aelatik's comment as answer
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GrahamSkan
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question