Home All Groups Group Topic Archive Search About

Copying files in VB.NET 2005

Author
14 Nov 2006 11:42 PM
Edhy Rijo [Progytech]
Hi All,

I am learning VB.NET and building small application that will do the following:
  1.. Copy all files from a DVD to a specific folder in the hard drive and overwrite all files always.
The problem I am facing is that the copy statement I am using is that when overwriting the files it will prompt for each file, so I can not find an option to tell it to overwrite all.

  If strCopyToFolder.EndsWith("\") = False Then
      strCopyToFolder += "\"
  End If
  'Dim instance As New FileIO.UIOption
  For Each strFoundFile As String In My.Computer.FileSystem.GetFiles(Me.cboCDDrives.Text, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
      My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder & strFoundFile.Substring(3), FileIO.UIOption.AllDialogs, _
      FileIO.UICancelOption.DoNothing)
      ' My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder & strFoundFile.Substring(3), True, FileIO.UICancelOption.DoNothing)

  Next

As you can see I have tried with two ways to copying the files and since these DVD may have up to 7GB of data, I want to show the user the progress of the copying and then inform the user when the copying operation is completed.

I would appreciate if anybody can point me to the right direction here, taking into consideration that I am really new to VB.NET (just 2 weeks of reading books).  My developer experience is with Visual FoxPro and I could have done this little project in not time with VFP, but I do want to get used to VB.NET.



--
Edhy Rijo
www.progytech.com
Bronx New York
ProMatrix MVP Life

Author
16 Nov 2006 11:36 PM
Ken Tucker [MVP]
Hi,

        Try something like this

        Dim strFiles As ReadOnlyCollection(Of String) =
My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.CurrentDirectory,
FileIO.SearchOption.SearchAllSubDirectories, "*.*")
        ProgressBar1.Maximum = strFiles.Count
        For x As Integer = 0 To strFiles.Count - 1
            Dim strFoundFile As String = strFiles(x)
            ProgressBar1.Value = x
            My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
strFoundFile.Substring(3), FileIO.UIOption.AllDialogs, _
            FileIO.UICancelOption.DoNothing)
            ' My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder
& strFoundFile.Substring(3), True, FileIO.UICancelOption.DoNothing)

        Next
        ProgressBar1.Value = strFiles.Count

Ken
------------------
"Edhy Rijo [Progytech]" <er***@progytech.com> wrote in message
news:uZ4TZaECHHA.5068@TK2MSFTNGP02.phx.gbl...
Hi All,

I am learning VB.NET and building small application that will do the
following:
Copy all files from a DVD to a specific folder in the hard drive and
overwrite all files always.
The problem I am facing is that the copy statement I am using is that when
overwriting the files it will prompt for each file, so I can not find an
option to tell it to overwrite all.

If strCopyToFolder.EndsWith("\") = False Then
    strCopyToFolder += "\"
End If
'Dim instance As New FileIO.UIOption
For Each strFoundFile As String In
My.Computer.FileSystem.GetFiles(Me.cboCDDrives.Text,
FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
strFoundFile.Substring(3), FileIO.UIOption.AllDialogs, _
    FileIO.UICancelOption.DoNothing)
    ' My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
strFoundFile.Substring(3), True, FileIO.UICancelOption.DoNothing)
Next

As you can see I have tried with two ways to copying the files and since
these DVD may have up to 7GB of data, I want to show the user the progress
of the copying and then inform the user when the copying operation is
completed.

I would appreciate if anybody can point me to the right direction here,
taking into consideration that I am really new to VB.NET (just 2 weeks of
reading books).  My developer experience is with Visual FoxPro and I could
have done this little project in not time with VFP, but I do want to get
used to VB.NET.



--
Edhy Rijo
www.progytech.com
Bronx New York
ProMatrix MVP Life
Author
17 Nov 2006 6:52 AM
Edhy Rijo [Progytech]
Hi Ken,

Thanks a lot for this code you put me in the right path.

--
Edhy Rijo
www.progytech.com
Bronx New York
ProMatrix MVP Life


  "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:%239JXRgdCHHA.1012@TK2MSFTNGP04.phx.gbl...
  Hi,

          Try something like this

          Dim strFiles As ReadOnlyCollection(Of String) =
  My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.CurrentDirectory,
  FileIO.SearchOption.SearchAllSubDirectories, "*.*")
          ProgressBar1.Maximum = strFiles.Count
          For x As Integer = 0 To strFiles.Count - 1
              Dim strFoundFile As String = strFiles(x)
              ProgressBar1.Value = x
              My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
  strFoundFile.Substring(3), FileIO.UIOption.AllDialogs, _
              FileIO.UICancelOption.DoNothing)
              ' My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder
  & strFoundFile.Substring(3), True, FileIO.UICancelOption.DoNothing)

          Next
          ProgressBar1.Value = strFiles.Count

  Ken
  ------------------
  "Edhy Rijo [Progytech]" <er***@progytech.com> wrote in message
  news:uZ4TZaECHHA.5068@TK2MSFTNGP02.phx.gbl...
  Hi All,

  I am learning VB.NET and building small application that will do the
  following:
  Copy all files from a DVD to a specific folder in the hard drive and
  overwrite all files always.
  The problem I am facing is that the copy statement I am using is that when
  overwriting the files it will prompt for each file, so I can not find an
  option to tell it to overwrite all.

  If strCopyToFolder.EndsWith("\") = False Then
      strCopyToFolder += "\"
  End If
  'Dim instance As New FileIO.UIOption
  For Each strFoundFile As String In
  My.Computer.FileSystem.GetFiles(Me.cboCDDrives.Text,
  FileIO.SearchOption.SearchAllSubDirectories, "*.*")
      My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
  strFoundFile.Substring(3), FileIO.UIOption.AllDialogs, _
      FileIO.UICancelOption.DoNothing)
      ' My.Computer.FileSystem.CopyFile(strFoundFile, strCopyToFolder &
  strFoundFile.Substring(3), True, FileIO.UICancelOption.DoNothing)
  Next

  As you can see I have tried with two ways to copying the files and since
  these DVD may have up to 7GB of data, I want to show the user the progress
  of the copying and then inform the user when the copying operation is
  completed.

  I would appreciate if anybody can point me to the right direction here,
  taking into consideration that I am really new to VB.NET (just 2 weeks of
  reading books).  My developer experience is with Visual FoxPro and I could
  have done this little project in not time with VFP, but I do want to get
  used to VB.NET.



  --
  Edhy Rijo
  www.progytech.com
  Bronx New York
  ProMatrix MVP Life