Link to home
Start Free TrialLog in
Avatar of rtananthan
rtananthan

asked on

how to copy a file from a given location to another

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
ASKER CERTIFIED SOLUTION
Avatar of aelatik
aelatik
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
What is your exact statement and what was the error?
Try this:
Shell "cmd /C copy file1_path_name file2_path_name"

This will simply let the OS do the copy for you
Avatar of CleanupPing
CleanupPing

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.
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