473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB code to Copy a Folder to another Location

AR Ratheesh
Dear all,
How to copy files or folders from one location to another.
Thank you in advance..
Sep 29 '09 #1
5 3887
Guido Geurs
767 Expert 512MB
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
Oct 13 '09 #2
Guido Geurs
767 Expert 512MB
dear,

You don't need to declare the function if You add the "Microsoft Scripting Runtime" reference to your project !
Oct 13 '09 #3
smartchap
236 100+
May have a look at the following link:

http://www.planet-source-code.com/vb...71156&lngWId=1
Oct 14 '09 #4
.. 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
Oct 21 '09 #5
Thank you for all.
Rathesh
Oct 21 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
8
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: ApexData | last post by:
I have a Split Database. FE / BE. It has been working fine, on a server for months. The BE exists in a secure folder used by 5 users who have full rights to the application. A number of other...
1
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
Hi, I have seen many examples of moving a folder to a new location, but is there a way to simply copy it instead? For example, I want to copy the contents of folder C:\Testing\Stuff to...
27
by: Jonathan Wood | last post by:
Greetings, I'd like to write any number of classes and then use those classes from any number of .NET applications. Since we've supposedly left "DLL Hell" and ActiveX objects behind, what has...
8
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move...
9
by: AWW | last post by:
Running XP - Visual Studio 2005 - VB Want to have duplicate projects - one safe and stable - other for experimenting Can't fine easy way to make duplicate project. Stupid question? or stupid ME?...
10
by: Jason | last post by:
I want to create a simple program with Two buttons on the form. BUTTON 1 - BACKUP PREFS this will do the following: Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla...
1
by: veer | last post by:
hi it looks a silly question but i m getting confused actually i want to copy folders from one location to another like from C:\abc To D:\xyz here abc and xyz are two folders in c and d drive it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.