?
Solved

ordering of files in a FileListBox

Posted on 2011-03-05
7
Medium Priority
?
1,405 Views
Last Modified: 2012-05-11
Hi,
I need to know how the files are listed in a filelistbox. Are they always in alphebetical order, or are they in the same order the files are added to the folder ? Can this order be changed, for example, to the order of the creation dates ?

Right now the folders I am using my two new programs with, have all three things going for them. They were added to their folders in the order of creation, which is also the alphabetical order. I need to know what will happen if I use these programs on a folder whose files are in some other order.

Thank you.
0
Comment
Question by:ChLa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35043778
FileListBox reads the files by sorting them by their name.
0
 

Author Comment

by:ChLa
ID: 35044347
OK, so a filelistbox is populated in alphabetical order. If the filelistbox remains open and is not repopulated, and some files are renamed, does the file order stay the same in the listbox, or are they re-ordered ?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35044380
You can add ShellChangeNotifier and add the code below on files change:
procedure TForm1.ShellChangeNotifier1Change;
begin
  FileListBox1.Update;
end;

Open in new window


Or use ShellListView that has AutoRefresh property.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35044424

FileListBox is always sorted alphabetically even if a new item is added

If you want a different sort, you have to implement it yourself
0
 

Author Comment

by:ChLa
ID: 35058395
Here's the thing,
I have written a program that renames and renumbers files,.I have used it successfully a few times on folders containing 3500 files each. I use a while-do loop to run through the files until all the files have been renamed. I retrieve the file names like this: name = FileListBox1.Items.Strings[filenumber], and then rename it. The file number increments and I go to the next name until filenumber = FileListBox1.Items.Count - 1. What I understand now is that if I rename a file so it is no longer in the same postion alphabetically, it will move in the FileListBox. For example, If I rename the first file, FileListBox1.Items.Files[0], from A0001.tif, to Z0001.tif, it would move to the end of the list and the third file would become FileListBox.Items.Strings[1], the second file on the list. Now my program would rename the third file, A0003.tif to Z0002.tif, thinking it was the second file, and so on. Now the files would be out of order, incorrectly numbered, and only every other file would be renamed. This would be a disaster.
What should I do to make the program bulletproof ? Is there a way to make the FileListBox freeze the ordering process while my program runs ? Should I copy the filenames from the FilelLstBox to something else, another kind of listbox, or an array for example, so the files will stay in the same order while being renamed ? Or do I need to make sure the new filename will never take the files out of order ? Generally, I want the files in the list box to be listed alphabetically, but to stay in the same order even though they may now be out of order allphabetically, until the renaming is done and I refresh the FileListBox.
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35066136

If you call BeginUpdate and EndUpdate, the list will not be modified until you are done, this will e even faster

FileListBox1.Item.BeginUpdate;
try
  //do your loop here
finally
  FileListBox1.Item.EndUpdate;
end;

But my recommendation is to save the list to a temporary list then work from that eg
var
  TempList: TStringList;
begin
  TempList := TStringList.Create;
  try
    TempList.Assign(FileListBox.Items);
    FileListBox1.Item.BeginUpdate;
   try
      //here do your loop accessing the TempList
     while filenumber < TempList.Count do
     begin
           FileName := TempList.Items.Strings[filenumber];

           //your rename code
         Inc(filenumber);
      end;
   finally
     //refresh the list box then endupdate
     FileListBox1.Item.EndUpdate;
   end;
  finally
    FreeAndNil(TempList);
  end;
end;
0
 
LVL 24

Accepted Solution

by:
jimyX earned 200 total points
ID: 35068893
> "does the file order stay the same in the listbox, or are they re-ordered ?"

No, you can go through the FileListBox items and rename safely, it does not re-order until you call "FileListBox1.Update;"
While filenumber <= FileListBox1.Items.Count - 1 do
  begin
    // rename the files
  end;
FileListBox1.Update;

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question