copying a file

RatDan

Member
Joined
Sep 26, 2006
Messages
10
Programming Experience
Beginner
Hello everyone,
I'm trying to write a simple program where a user click on a button and it copy all the file in drive D for example and store it in drive E. The program will be running in windows 98. If you can post sample code.
Thanks.
 
Last edited:
do you know anything about threading? if so, this would be of interest to you:
VB.NET:
Option Explicit On 
Option Strict On

Imports System.IO

Friend Class CopyFiles
    Friend Event Successful()
    Friend Event Failed(ByVal Reason As String)

    Private mstrSource As String
    Private mstrDestination As String

    Friend Sub StartCopying()
        Try
            Call CopyDirectory(mstrSource, mstrDestination)
            RaiseEvent Successful()
        Catch ex As Exception
            RaiseEvent Failed(ex.Message)
        End Try
    End Sub

    Private Function CopyDirectory(ByVal Src As String, ByVal Dest As String) As Boolean
        'add Directory Seperator Character (\) for the string concatenation shown later
        If Dest.Substring(Dest.Length - 1, 1) <> Path.DirectorySeparatorChar Then Dest += Path.DirectorySeparatorChar
        'If Directory.Exists(Dest) = False Then Directory.CreateDirectory(Dest)
        Dim Files() As String = Directory.GetFileSystemEntries(Src)
        For Each element As String In Files
            If Directory.Exists(element) = True Then
                'if the current FileSystemEntry is a directory,
                'call this function recursively
                Directory.CreateDirectory(Dest & Path.GetFileName(element))
                CopyDirectory(element, Dest & Path.GetFileName(element))
            Else
                'the current FileSystemEntry is a file so just copy it
                File.Copy(element, Dest & Path.GetFileName(element), True)
            End If
        Next element
    End Function

    Friend Property Source() As String
        Get
            Return mstrSource
        End Get
        Set(ByVal Value As String)
            mstrSource = Value
        End Set
    End Property

    Friend Property Destination() As String
        Get
            Return mstrDestination
        End Get
        Set(ByVal Value As String)
            mstrDestination = Value
        End Set
    End Property
End Class

if not then there's some explanations to be done, of which i can if you need help, i can also provide an example for you (using the code about) too
 
not really, I just want to write a program that when executed it will copy all the file in the F directory on the server machines to a C drive on the local machine.
 
here's an example of how to use it (with the threading as well)

feel free to spice it up and whatnot (like display the number of files copied) if you like
 
Back
Top