|
-
Jul 24th, 2008, 06:58 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Progress bar question
Heya guys
I have got a progress bar that i want to move in accordance with the process of copying files. Basically i am creating an update program that checkes to see if the version on the server is more up-to-date than the one on the local machine, then if it its up-to-date and open the file if its not up-to-date it deletes a set of files and then copies the files from the server to the local machine.
How can i get a progress bar to move in relation to how much of the progress is completed?
thank you in advance
Frosty
-
Jul 24th, 2008, 08:43 AM
#2
New Member
Re: Progress bar question
I'm quite new to VB myself, but what I would do personally is change the bar state every so often within the code.
vb Code:
'check a couple of files
Me.ProgressBar1.Value = 40
'check some more..
Me.ProgressBar1.Value = 80
'etc etc
'if they need updating, probably cycle the bar backwards
Me.ProgressBar1.Value = 50
'etc etc again
But like I said, I'm new so excuse me if I'm.. way off.
-
Jul 24th, 2008, 09:33 AM
#3
Member
Re: Progress bar question
You'd want to set the ProgressBars's Step and Maximum values. Then call the PerformStep at appropriate times. If you had 50 files to download then Maximum would be 50 and Step would be 1 and each time a file downloads, call PerformStep. If you're working with one large file you'll have to check its size vs its maximum size. My.Computer.FileSystem.GetFileInfo will get you the file size.
-
Jul 24th, 2008, 10:20 AM
#4
Re: Progress bar question
is this all local as in your copies are being made via normal file copy, or is the server being accessed via HTTP/FTP?
-
Jul 24th, 2008, 10:25 AM
#5
Member
Re: Progress bar question
I was assuming wherever the source is, you'd be able to request the file size before the download, then check it against the size of the file you have locally.
-
Jul 24th, 2008, 11:48 AM
#6
Thread Starter
Fanatic Member
Re: Progress bar question
it is all done locally over a network there is no HTTp/FTP involved.
I have got the idea of copying all teh files etc working its just the progress bar that i am struggling with
-
Jul 24th, 2008, 11:51 AM
#7
Re: Progress bar question
well as was mentioned earlier in this thread, if you know the number of files you are going to copy ahead of time, you can just set the progressbars max to that value, and increment it by 1 each time a file is copied. While size will matter and fluctuate the actual copy times of each file, the progessbar itself is not a measure of time, its a measure of progress, so I wouldn't even bother calculating file sizes to work into the progressbar's updating. Especially if its over a local network, since file copies should be relatively quick.
-
Jul 24th, 2008, 12:29 PM
#8
Thread Starter
Fanatic Member
Re: Progress bar question
how can i copy all the files in and individual folder seperatly adn increment the progress bar with each one. What if i dont know how many files there are in thr first place? Is there anyway you can search a folder to get how many files are in there?
-
Jul 24th, 2008, 12:31 PM
#9
Re: Progress bar question
You mentioned
"I have got the idea of copying all teh files etc working its just the progress bar that i am struggling with"
so what does that code look like now?
-
Jul 24th, 2008, 12:35 PM
#10
Thread Starter
Fanatic Member
Re: Progress bar question
it looks like this at the moment:
Code:
My.Computer.FileSystem.DeleteDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System", FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System")
My.Computer.FileSystem.CopyDirectory("\\sqlserver\SQLServerHDD\PHC Admin System", My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System\")
-
Jul 24th, 2008, 01:49 PM
#11
Re: Progress bar question
the CopyDirectory method is just going to copy the entire directory and block your app until it is done. It doesn't report any progress, so you can't use it to know how far along it is.
You want to grab all the files in the directory, and copy them 1 by 1.
Try something like this:
Code:
Dim localDirectory As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System"
Dim remoteDirectory As String = "\\sqlserver\SQLServerHDD\PHC Admin System"
My.Computer.FileSystem.DeleteDirectory(localDirectory, FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.CreateDirectory(localDirectory)
Dim filesToCopy As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles(remoteDirectory)
ProgressBar1.Maximum = filesToCopy.Count
ProgressBar1.Value = 0
ProgressBar1.Minimum = 0
For Each fileName As String In filesToCopy
My.Computer.FileSystem.CopyFile(fileName, localDirectory & "\" & IO.Path.GetFileName(fileName), True)
ProgressBar1.Value += 1
Next
-
Jul 24th, 2008, 02:40 PM
#12
Thread Starter
Fanatic Member
Re: Progress bar question
will that also work if there are folders in there will it copy all the folders in there as well as the files
-
Jul 24th, 2008, 02:43 PM
#13
Re: Progress bar question
no, but it could be extended to do so.
-
Jul 24th, 2008, 03:32 PM
#14
Thread Starter
Fanatic Member
Re: Progress bar question
how could it be extended to include folders aswell?
-
Jul 24th, 2008, 03:34 PM
#15
Re: Progress bar question
by changing the line of code that grabs the files to this:
Code:
Dim filesToCopy As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles(remoteDirectory, FileIO.SearchOption.SearchAllSubDirectories)
-
Jul 24th, 2008, 03:52 PM
#16
Thread Starter
Fanatic Member
Re: Progress bar question
Brilliant thank you very much kleinma
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|