FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ProgressBar with foreach action

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Dec 20, 2007 2:52 pm    Post subject: ProgressBar with foreach action Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Dec 21, 2007 5:22 am    Post subject: Re: ProgressBar with foreach action Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Fri Dec 21, 2007 4:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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