Connecting Tech Pros Worldwide Help | Site Map

VB code to Copy a Folder to another Location

AR Ratheesh's Avatar
Newbie
 
Join Date: Jul 2009
Posts: 12
#1: Sep 29 '09
Dear all,
How to copy files or folders from one location to another.
Thank you in advance..
Newbie
 
Join Date: Oct 2009
Posts: 18
#2: Oct 13 '09

re: VB code to Copy a Folder to another Location


Dear,

You can copy, move, ... files and folders with FileCopy, Foldercopy,... with a FileSystemObject.

example: copies files from a list to a path entered in a textbox
==============================================
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
  2.    (ByVal lpExistingFileName As String, _
  3.    ByVal lpNewFileName As String, ByVal _
  4.    bFailIfExists As Long) As Long
-------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub Com_save_gekozene_Click()
  2. Dim i As Integer
  3. Dim TO_FILE As String
  4. Dim fso As New FileSystemObject
  5. '§ folder exist?
  6.    If Not fso.FolderExists(Text_to_path.Text) Then
  7.       MsgBox ("The folder don't exist!")
  8.       Exit Sub
  9.    End If
  10.    With List_gekozene
  11.       For i = 0 To .ListCount - 1
  12.          TO_FILE = Text_to_path.Text & "\" & Mid(.List(i), InStrRev(.List(i), "\") + 1)
  13. '§ file exist ?
  14.          If fso.FileExists(TO_FILE) Then
  15.             MsgBox TO_FILE & " file exist !"
  16.          Else
  17.             fso.CopyFile .List(i), TO_FILE
  18.             Label_status_copy.Caption = TO_FILE & " = GECOPIEERD"
  19.             DoEvents
  20.          End If
  21.       Next
  22.    End With
  23.    Label_status_copy.Caption = ""
  24. End Sub
Newbie
 
Join Date: Oct 2009
Posts: 18
#3: Oct 13 '09

re: VB code to Copy a Folder to another Location


dear,

You don't need to declare the function if You add the "Microsoft Scripting Runtime" reference to your project !
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#4: Oct 14 '09

re: VB code to Copy a Folder to another Location


May have a look at the following link:

http://www.planet-source-code.com/vb...71156&lngWId=1
Newbie
 
Join Date: Jul 2007
Posts: 6
#5: 4 Weeks Ago

re: VB code to Copy a Folder to another Location


.. May be this will help you TO COPY FILE OR FOLDER

Dim txtdbpath As String 'this is your database file
Dim txtdbpathcopy As String 'this is your copy path
Dim intResponse, fs
' the following double checks, Are you sure?
intResponse = MsgBox("Are you sure that you wish to make a copy of your file now?", vbYesNo + vbDefaultButton1 + vbQuestion, "Crystal Technosoft")
If (intResponse = 6) Then
Set fs = CreateObject("Scripting.FileSystemObject")
' txtdbpath = frmMain.cdgDialog.FileName
' txtdbpath = "D:\ABC.mdb"
txtdbpath = App.Path & "\" & "ABC.mdb"
txtdbpathcopy = "D:\"
fs.CopyFile txtdbpath, txtdbpathcopy, True
MsgBox "Done Successfully", vbInformation, "Crystal Technosoft"
Else
MsgBox "Not Done", vbCritical, "Crystal Technosoft"
End If
AR Ratheesh's Avatar
Newbie
 
Join Date: Jul 2009
Posts: 12
#6: 4 Weeks Ago

re: VB code to Copy a Folder to another Location


Thank you for all.
Rathesh
Reply