views:

83

answers:

3

I am programming in C++, Windows I wonder if I can get the order of files in a certain folder. the order of FileFind seems by alphabetic order.

For example. I can drag folders/files in a folder. and if I open it again, the order will remain. I wish I can get this order. Many Thanks!

Sorry for not stating my question clear enough. I thought the order in explorer is about file system. now I know from your answers, It is just explorer's order. Then ,How can I read the order from explorer.

The situation is as bellow: I am writting a image viewer, double-click an Image, open the window. and press "->" "<-", you can navigate the image folder. Users want the order of the navigation in my image viewer is just like the order in explorer. I don't know how to do it.

Is there any shell API todo this?

A: 

As much as i could understand from the problem stated. You need to split the application in parts.

  1. First get the list of files and directories and store it in a list. this code at MSDN may be helpful in getting some basic Win32 APIs to list files in a directory. Try tweaking it a bit to get the desired results as per your needs. Now once you have a list you can sort this in alphabetical order. You may use a basic linked list to store all the file names and path.
  2. The second step would be to use a GUI to display the list of these files. You can use a listbox where you can populate this list. Even listbox has an option where the list is sorted alphabetically. So you may not sort the list in step 1 if you using this option.
  3. For implementing drag and drop you would need to write code as to part part of the list or file is selected. In Win32 SDK you will get this notifications in terms of WM_xxx messages. For each GUI control be it listview or listbox etc MSDN will tell you what message to trap and use for knowing which file was dragged or selected.
Kavitesh Singh
A: 

I think what you're looking for is an internal implementation of Windows Explorer, and not a file system feature. For instance, try this drag and drop test into total commander. The order might be different. Also, bear in mind different users might have different views of the file system - one user might not be allowed to see some of the files; another might have already sorted the said directory.

Basically, the FindFirstFile API does not provide any way of sorting the results, and neither does any API that relies on it (such as MFC's CFileFind). See Raymond Chen's post: FindFirstFile is not a SQL query.

Quoting Raymond's words, you'll have to code it up yourself. Enumerate all files into a list, and sort it whatever way you want.

eran
A: 

IFolderView might do what you want, but I have no idea how to get it (not a shell programmer).

Luke