View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Dec 20, 2007 2:52 pm Post subject: ProgressBar with foreach action |
|
|
Greetings!
So, I have this foreach loop which is moving a bunch of files over to another directory. I would like to use the ProgressBar to let the user know how long the process still needs to go through. I don-t want to do a Timer count, but a file count progress. I have never used ProgressBar and I have seen and compiled the progress.d example, but I don-t know how to transfer the code to use count instead of time. So, the foreach looks like this:
Code: |
char[][] allfiles = std.file.listdir(fromDir,"*");
foreach(char[] f; allfiles)
{
char[] ffile = toDir[0 .. 1] ~ f[1 .. $];
char[] fdir = std.path.getDirName(f);
char[] tdir = std.path.getDirName(ffile);
CreateDirectory(tdir);
try
{
info.text = "moving " ~ f;
std.file.rename(f,ffile);
}
catch (FileException e)
{
error.text = "Error moving file: " ~ e.toString();
}
}
|
So, what I would like to happen is that for every file that I move, it moves the progressbar. I have tried a few things, but I can not seem to find it.
Any help would be greatly appreciated.
thanks,
jose |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Fri Dec 21, 2007 5:22 am Post subject: Re: ProgressBar with foreach action |
|
|
Set the ProgressBar's maximum property to something like the total bytes of all the files or the number of files, and increase the value by the number of bytes processed or the number of files done so far. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Fri Dec 21, 2007 4:36 pm Post subject: |
|
|
Thanks. I just didn-t understand the whole thing... Here is the code which works: Code: |
char[][] allfiles = std.file.listdir(fromDir,"*");
pBar.minimum = 0;
pBar.maximum = allfiles.length - 1;
pBar.step = 1;
foreach(char[] f; allfiles)
{
char[] ffile = toDir[0 .. 1] ~ f[1 .. $];
char[] fdir = std.path.getDirName(f);
char[] tdir = std.path.getDirName(ffile);
CreateDirectory(tdir);
try
{
info.text = "moving " ~ f;
std.file.rename(f,ffile);
}
catch (FileException e)
{
error.text = "Error moving file: " ~ e.toString();
}
pBar.performStep();
}
pBar.value = 0;
|
Thanks. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|