473,395 Members | 1,968 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,395 software developers and data experts.

Copying files in VB.NET 2005

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.Tex t, 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
Nov 14 '06 #1
2 8108
Hi,

Try something like this

Dim strFiles As ReadOnlyCollection(Of String) =
My.Computer.FileSystem.GetFiles(My.Computer.FileSy stem.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.comwrote in message
news:uZ**************@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.Tex t,
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
Nov 16 '06 #2
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.netwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

Try something like this

Dim strFiles As ReadOnlyCollection(Of String) =
My.Computer.FileSystem.GetFiles(My.Computer.FileSy stem.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.comwrote in message
news:uZ**************@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.Tex t,
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
Nov 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
0
by: Dan | last post by:
We debug a VB.Net App that uses compact framework to a DAP Windows CE.Net device. When I debug I would like to only have the EXE copied down. Right now it copies any referrences as well and...
21
by: hermes_917 | last post by:
I want to use memcpy to copy the contents of one struct to another which is a superset of the original struct (the second struct has extra members at the end). I wrote a small program to test...
16
by: NoodNutt | last post by:
G'day ppl Is there a process whereby I can copy the text labels of all the files in a root directory? I recall going back a long way seeing something about it but did not take any notice as I...
1
by: chris.atlee | last post by:
I'm writing a program in python that creates tar files of a certain maximum size (to fit onto CD/DVD). One of the problems I'm running into is that when using compression, it's pretty much...
4
by: Robert Iver | last post by:
Hello everyone, I am trying to create an application that utilizes a SQL Mobile database. I have included that database in my main project, and it compiles and debugs just fine. I then...
6
by: Ryan | last post by:
I have 2 Access '97 databases. I am trying to migrate all the data from one to the other (append to existing records). I do not have Access '97 and opening with Access XP or later causes...
0
by: mlfblom | last post by:
Hi, I am running visual studio 2005 on a Vista Ultimate client. I have created a remote site on a Windows 2003 R2 server. This site has about 100 aspx, many App_Code files and several references...
2
by: schneider | last post by:
Hi all, I want to publish my asp.net 2.0 website using the "publish website" feature of visual studio 2005. everything works fine so far, but the IDE only compiles and copies the aspx, ascx,...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.