0

Say a directory contains the following sixteen files:

pos1_conf1_1_OS_1state_lbs.out
pos1_conf1_1_OS_3state_lbs.out
pos1_conf2_1_OS_1state_lbs.out
pos1_conf2_1_OS_3state_lbs.out
pos2_conf1_1_OS_1state_lbs.out
pos2_conf1_1_OS_3state_lbs.out
pos3_conf1_1_OS_1state_lbs.out
pos3_conf1_1_OS_3state_lbs.out
pos4_conf1_1_OS_1state_lbs.out
pos4_conf1_1_OS_3state_lbs.out
pos5_conf1_1_OS_1state_lbs.out
pos5_conf1_1_OS_3state_lbs.out
pos5_conf2_1_OS_1state_lbs.out
pos5_conf2_1_OS_3state_lbs.out
pos6_conf1_1_OS_1state_lbs.out
pos6_conf1_1_OS_3state_lbs.out

If I open them all at once, by "File->Open" or "Drag&Drop", the files are opened in completely random order.

sample picture

It should be noted that this happens both in commercial software such as ChemDraw and home-made utilities. I am wondering how to interpret or even control this random order of the files opened by MDI applications?

SOUser
  • 3,802
  • 5
  • 33
  • 63
  • 2
    They are opened in the order the OS (Windows) sends them to the app. That may appear random, it could also simply be "natural order": the order in which they were added to the folder. Don't confuse this with timestamps, not even the created date, as a file keeps its original timestamps when moved to another folder. – Marjan Venema May 06 '12 at 11:20
  • 1
    Isn't it your code that's opening the files? Is this problem related to being an MDI application? – Sertac Akyuz May 06 '12 at 14:33
  • @MarjanVenema: Thank you for your comments! I didn't know these before! I wonder, if I select some files in Windows Explorer and press Enter to open these files in commercial closed source softwares, how to intercept and change the order? For home-made utilities, I could sort the files before reading in the content. – SOUser May 06 '12 at 17:28
  • @SertacAkyuz: Thank you very much for your comment! This phenomenon happens both with my home-made utilities and commercial softwares. It could be related to MDI but I am not sure. – SOUser May 06 '12 at 17:28
  • 1
    For closed software: there might be some hooks in the Windows API that you could use. For your own: it depends on how Windows start your app: just once with all the files as parameters, or once for each file (you would have to take steps yourself in subsequent instances to send them through to the first instance and then terminate). In the former case you can sort, in the latter case there is not much you can do as you never know when the last file will arrive. – Marjan Venema May 06 '12 at 17:34
  • @MarjanVenema: Thank you for your comments! Do you happen to know what hooks should I look into? Search on the internet didn't give me any hints. – SOUser May 06 '12 at 19:30
  • 1
    Sorry, no, no experience with that. – Marjan Venema May 06 '12 at 19:57

1 Answers1

2

If I recall correctly, the file dialog returns the file with the focus rectangle first, and then the remaining files are in the order in which the dialog displayed them. There is no way for you to change this behaviour so if you don't like it you will have to sort the files.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • @DavidHaffernan: Thank you for your comments very much! Do you happen to know some hooks that I could intercept and change the order of the files, before the associated application begins? – SOUser May 06 '12 at 19:35
  • 1
    I don't think there are any hooks, not official ones anyway – David Heffernan May 06 '12 at 19:41