Sunday, May 1, 2011

Change file order in a Windows Directory in C

Like when you drag a file on top of another one and change the order, like that.

From stackoverflow
  • There is no way to do this (except maybe by hacking the directory structures on the disk using raw, sector-based APIs). The order of files on the disk is managed by the file system according to it's design and needs.

    dreamlax : I think he's talking in terms of Windows Explorer, how it retains the order and position of files in folders, on the Desktop etc.
    Michael Burr : Oh, I thought he meant something like so that FindNextFile() would return them in a particular order.
    RBerteig : Which can only be done on FAT, and not on NTFS which keeps directory entries in some flavor of tree structure and so the only order is the natural order of that tree. There used to be shareware tools that would sort the FAT directory entries, back in the day.
  • I'm going to assume you're asking about how to rearrange the order in which files are displayed in a folder. I'm not exactly sure how to do it, but you'll want to use the various functions from the Windows shell to accomplish this. See the Shell Developer's Guide.

  • For what its worth, FAT directory entries are stored in the order in which they are added. NTFS actually indexes its directory entries, but I thought creation order still played some role in which order they're retrieved. Maybe not. Nearly every UI that does file listings does some type of sorting on display, though, usually alphabetical.

    Bottom line-- if its not application-sorted and its not creation time, then there's nothing you can do.

0 comments:

Post a Comment