[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Points for S-Twilley

Hi S-Twilley

Points from other question you answered, can u tell me how to copy all files in a folder??

Was just thinking instead of updating my exe why not just copy down anything put into folder on network. That way its uptodate with all project files (Config, dll, exs etc)

cheers

George
0
Geo123
Asked:
Geo123
  • 3
  • 2
  • 2
1 Solution
 
RonaldBiemansCommented:
Public Sub CopyFolder(ByVal pathSource As String, ByVal pathDestination As String)

    If Not System.IO.Directory.Exists(pathSource) Then
      Throw New System.IO.DirectoryNotFoundException("Source folder '" & pathSource & "' not found")
    ElseIf Not System.IO.Directory.Exists(pathDestination) Then
      Throw New System.IO.DirectoryNotFoundException("Destination folder '" & pathSource & "' not found")
    Else

      Try

        Dim fileList() As String = System.IO.Directory.GetFiles(pathSource)

        Dim fileTarget As String

        For Each fileSource As String In fileList

          fileTarget = fileSource.Replace(pathSource, pathDestination)

          System.IO.File.Copy(fileSource, fileTarget)

        Next

      Catch ex As Exception

      End Try

    End If

  End Sub
0
 
RonaldBiemansCommented:
I know the points are for S-twilley, but I was just using this :-)
0
 
Geo123Author Commented:
Thanks Ronald was just looking through questions and see S-twilley had already answered someone else on this...I added in your error trapping and got this

Many thanks George

    Private myFileNetDrive As String = "\\MyNetworkPath\"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not System.IO.Directory.Exists(myFileNetDrive) Then
            Throw New System.IO.DirectoryNotFoundException("Source folder '" & myFileNetDrive & "' not found")
        Else
            Try
                Dim di As New System.IO.DirectoryInfo(myFileNetDrive)

                For Each fi As System.IO.FileInfo In di.GetFiles("*.*")
                    'lblStatus.Refresh()
                    If fi.Extension <> ".mdb" Then
                        fi.CopyTo("C:\test\" & fi.Name)
                    End If
                Next
                Me.Close()

            Catch ex As Exception
                MsgBox("Friendly Error message, " & ex.ToString & "and" & ex.Message)  ' Show friendly error message.
            End Try
        End If
    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
S-TwilleyCommented:
Thanks for helping out Ronald... I've just been out renewing my passport (off to Prague in a few weeks hopefully)
0
 
RonaldBiemansCommented:
Ha Prague, beautifull city and the beer is cheap, but ofcourse you are only going there for cultural visits ;-).
0
 
S-TwilleyCommented:
Don't think I'll get much culture in 2 days... have a friend travelling around Europe for 3 months, we're going to try and catch him while he's in Prague though... and I hear the beer is about 70p a pint (so definately cheap as you said)
0
 
Geo123Author Commented:
Hi guys... I have been to Paris but keep meaning to goto Prague just never get round to it.
0

Featured Post

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.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now