What order were files/directories output in dir?












11















In the version of command.com included with MS-DOS, DIR seems to print files in a random order, but if one runs multiple DIR commands, they all print the files in the same order. This order does not appear to be based on date, size, or alphabetization. So what is the order? Does it simply print whatever files it finds first?










share|improve this question









New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

    – phuclv
    Apr 19 at 16:55











  • As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

    – Bill Hileman
    yesterday
















11















In the version of command.com included with MS-DOS, DIR seems to print files in a random order, but if one runs multiple DIR commands, they all print the files in the same order. This order does not appear to be based on date, size, or alphabetization. So what is the order? Does it simply print whatever files it finds first?










share|improve this question









New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

    – phuclv
    Apr 19 at 16:55











  • As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

    – Bill Hileman
    yesterday














11












11








11


1






In the version of command.com included with MS-DOS, DIR seems to print files in a random order, but if one runs multiple DIR commands, they all print the files in the same order. This order does not appear to be based on date, size, or alphabetization. So what is the order? Does it simply print whatever files it finds first?










share|improve this question









New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












In the version of command.com included with MS-DOS, DIR seems to print files in a random order, but if one runs multiple DIR commands, they all print the files in the same order. This order does not appear to be based on date, size, or alphabetization. So what is the order? Does it simply print whatever files it finds first?







ms-dos






share|improve this question









New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Apr 19 at 17:39









Stephen Kitt

41.1k8169177




41.1k8169177






New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Apr 18 at 23:38









TSJNachos117TSJNachos117

1585




1585




New contributor




TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






TSJNachos117 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1





    related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

    – phuclv
    Apr 19 at 16:55











  • As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

    – Bill Hileman
    yesterday














  • 1





    related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

    – phuclv
    Apr 19 at 16:55











  • As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

    – Bill Hileman
    yesterday








1




1





related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

– phuclv
Apr 19 at 16:55





related: Default file order of "dir" command in Windows console, What order does the DIR command arrange files if no sort order is specified?

– phuclv
Apr 19 at 16:55













As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

– Bill Hileman
yesterday





As an early DOS user (1.0, I think) it used to bug me that it would not show files and later (in DOS 2.0 and above) folders in alphabetical order. Norton Utilities solved that by providing ds.com (.exe?) or dirsort which allowed you to do just that, sort your files and folders in whatever order you prefered, with an /s switch to do sub-folders as well. I think I used ds more than any other command before the version of DOS came out where alphabetical was the default order. I used ts (textsearch) a lot, too.

– Bill Hileman
yesterday










3 Answers
3






active

oldest

votes


















29














When a new file is created in a FAT-based file system, its entry will be placed in the first vacant directory slot, if there is one, or else the directory will be extended to add another cluster worth of vacant slots (and the new entry will be placed in the first of those). If no files are ever deleted, files will be assigned directory entries in the order of creation.



Before the advent of long file names, each file that was deleted would result in an empty directory slot, which would get filled by the next file to be created. Long file names complicate this process because they are stored using multiple consecutive directory slots (though I don't know the exact process).



The "dir" command in MS-DOS defaults to reporting files in the same order as their directory entries, but command-line arguments in later versions allow sorting by various criteria.






share|improve this answer
























  • Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

    – fernando.reyes
    Apr 19 at 18:55











  • And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

    – dirkt
    2 days ago



















22














DIR lists files in the order they’re returned by the find first and find next calls.



On FAT file systems, RAM drives, CD-ROMs etc. this is the order of the directory entries on disk, which on FAT file systems is file creation order as long as no files are deleted. On network file systems, it’s whatever order the server and redirector choose. Other file system drivers can exhibit different behaviour; thus on HPFS and NTFS, which sort directories’ contents on disk, files are returned in the file systems sort order (as can be seen in OS/2 or Windows virtual DOS boxes on HPFS or NTFS volumes).



There are tools which will re-order entries on disk, to provide a permanent sort order for DIR. Defragmenting could also re-order files (commonly, directories first, then files).



DOS 5 added various sorting options to DIR itself; the order then depends only on those, when present.






share|improve this answer


























  • A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

    – JdeBP
    Apr 19 at 17:41



















4














Whatever it finds first. DIR in MS-DOS command.com starts at the beginning of the directory table and reads it through to the end. The files will be in the order they were added to the directory table.






share|improve this answer



















  • 1





    "The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

    – a CVn
    Apr 20 at 18:51












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "648"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






TSJNachos117 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f9748%2fwhat-order-were-files-directories-output-in-dir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









29














When a new file is created in a FAT-based file system, its entry will be placed in the first vacant directory slot, if there is one, or else the directory will be extended to add another cluster worth of vacant slots (and the new entry will be placed in the first of those). If no files are ever deleted, files will be assigned directory entries in the order of creation.



Before the advent of long file names, each file that was deleted would result in an empty directory slot, which would get filled by the next file to be created. Long file names complicate this process because they are stored using multiple consecutive directory slots (though I don't know the exact process).



The "dir" command in MS-DOS defaults to reporting files in the same order as their directory entries, but command-line arguments in later versions allow sorting by various criteria.






share|improve this answer
























  • Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

    – fernando.reyes
    Apr 19 at 18:55











  • And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

    – dirkt
    2 days ago
















29














When a new file is created in a FAT-based file system, its entry will be placed in the first vacant directory slot, if there is one, or else the directory will be extended to add another cluster worth of vacant slots (and the new entry will be placed in the first of those). If no files are ever deleted, files will be assigned directory entries in the order of creation.



Before the advent of long file names, each file that was deleted would result in an empty directory slot, which would get filled by the next file to be created. Long file names complicate this process because they are stored using multiple consecutive directory slots (though I don't know the exact process).



The "dir" command in MS-DOS defaults to reporting files in the same order as their directory entries, but command-line arguments in later versions allow sorting by various criteria.






share|improve this answer
























  • Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

    – fernando.reyes
    Apr 19 at 18:55











  • And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

    – dirkt
    2 days ago














29












29








29







When a new file is created in a FAT-based file system, its entry will be placed in the first vacant directory slot, if there is one, or else the directory will be extended to add another cluster worth of vacant slots (and the new entry will be placed in the first of those). If no files are ever deleted, files will be assigned directory entries in the order of creation.



Before the advent of long file names, each file that was deleted would result in an empty directory slot, which would get filled by the next file to be created. Long file names complicate this process because they are stored using multiple consecutive directory slots (though I don't know the exact process).



The "dir" command in MS-DOS defaults to reporting files in the same order as their directory entries, but command-line arguments in later versions allow sorting by various criteria.






share|improve this answer













When a new file is created in a FAT-based file system, its entry will be placed in the first vacant directory slot, if there is one, or else the directory will be extended to add another cluster worth of vacant slots (and the new entry will be placed in the first of those). If no files are ever deleted, files will be assigned directory entries in the order of creation.



Before the advent of long file names, each file that was deleted would result in an empty directory slot, which would get filled by the next file to be created. Long file names complicate this process because they are stored using multiple consecutive directory slots (though I don't know the exact process).



The "dir" command in MS-DOS defaults to reporting files in the same order as their directory entries, but command-line arguments in later versions allow sorting by various criteria.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 19 at 2:40









supercatsupercat

8,195942




8,195942













  • Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

    – fernando.reyes
    Apr 19 at 18:55











  • And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

    – dirkt
    2 days ago



















  • Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

    – fernando.reyes
    Apr 19 at 18:55











  • And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

    – dirkt
    2 days ago

















Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

– fernando.reyes
Apr 19 at 18:55





Some details about long file names, by Raymond Chen: devblogs.microsoft.com/oldnewthing/20110826-00/?p=9793

– fernando.reyes
Apr 19 at 18:55













And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

– dirkt
2 days ago





And with the knowledge that new entries will be placed in the first vacant slot, you could actually manually order the directory with carefully ordered DEL and COPY operations (I have done that).

– dirkt
2 days ago











22














DIR lists files in the order they’re returned by the find first and find next calls.



On FAT file systems, RAM drives, CD-ROMs etc. this is the order of the directory entries on disk, which on FAT file systems is file creation order as long as no files are deleted. On network file systems, it’s whatever order the server and redirector choose. Other file system drivers can exhibit different behaviour; thus on HPFS and NTFS, which sort directories’ contents on disk, files are returned in the file systems sort order (as can be seen in OS/2 or Windows virtual DOS boxes on HPFS or NTFS volumes).



There are tools which will re-order entries on disk, to provide a permanent sort order for DIR. Defragmenting could also re-order files (commonly, directories first, then files).



DOS 5 added various sorting options to DIR itself; the order then depends only on those, when present.






share|improve this answer


























  • A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

    – JdeBP
    Apr 19 at 17:41
















22














DIR lists files in the order they’re returned by the find first and find next calls.



On FAT file systems, RAM drives, CD-ROMs etc. this is the order of the directory entries on disk, which on FAT file systems is file creation order as long as no files are deleted. On network file systems, it’s whatever order the server and redirector choose. Other file system drivers can exhibit different behaviour; thus on HPFS and NTFS, which sort directories’ contents on disk, files are returned in the file systems sort order (as can be seen in OS/2 or Windows virtual DOS boxes on HPFS or NTFS volumes).



There are tools which will re-order entries on disk, to provide a permanent sort order for DIR. Defragmenting could also re-order files (commonly, directories first, then files).



DOS 5 added various sorting options to DIR itself; the order then depends only on those, when present.






share|improve this answer


























  • A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

    – JdeBP
    Apr 19 at 17:41














22












22








22







DIR lists files in the order they’re returned by the find first and find next calls.



On FAT file systems, RAM drives, CD-ROMs etc. this is the order of the directory entries on disk, which on FAT file systems is file creation order as long as no files are deleted. On network file systems, it’s whatever order the server and redirector choose. Other file system drivers can exhibit different behaviour; thus on HPFS and NTFS, which sort directories’ contents on disk, files are returned in the file systems sort order (as can be seen in OS/2 or Windows virtual DOS boxes on HPFS or NTFS volumes).



There are tools which will re-order entries on disk, to provide a permanent sort order for DIR. Defragmenting could also re-order files (commonly, directories first, then files).



DOS 5 added various sorting options to DIR itself; the order then depends only on those, when present.






share|improve this answer















DIR lists files in the order they’re returned by the find first and find next calls.



On FAT file systems, RAM drives, CD-ROMs etc. this is the order of the directory entries on disk, which on FAT file systems is file creation order as long as no files are deleted. On network file systems, it’s whatever order the server and redirector choose. Other file system drivers can exhibit different behaviour; thus on HPFS and NTFS, which sort directories’ contents on disk, files are returned in the file systems sort order (as can be seen in OS/2 or Windows virtual DOS boxes on HPFS or NTFS volumes).



There are tools which will re-order entries on disk, to provide a permanent sort order for DIR. Defragmenting could also re-order files (commonly, directories first, then files).



DOS 5 added various sorting options to DIR itself; the order then depends only on those, when present.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 19 at 18:52

























answered Apr 19 at 5:44









Stephen KittStephen Kitt

41.1k8169177




41.1k8169177













  • A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

    – JdeBP
    Apr 19 at 17:41



















  • A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

    – JdeBP
    Apr 19 at 17:41

















A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

– JdeBP
Apr 19 at 17:41





A VDM in OS/2 or Windows NT was a third case, halfway between. Local disc volumes weren't presented as network redirected, but neither were the underlying filesystems unsorted. They were often HPFS or NTFS where directories are sorted by their nature.

– JdeBP
Apr 19 at 17:41











4














Whatever it finds first. DIR in MS-DOS command.com starts at the beginning of the directory table and reads it through to the end. The files will be in the order they were added to the directory table.






share|improve this answer



















  • 1





    "The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

    – a CVn
    Apr 20 at 18:51
















4














Whatever it finds first. DIR in MS-DOS command.com starts at the beginning of the directory table and reads it through to the end. The files will be in the order they were added to the directory table.






share|improve this answer



















  • 1





    "The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

    – a CVn
    Apr 20 at 18:51














4












4








4







Whatever it finds first. DIR in MS-DOS command.com starts at the beginning of the directory table and reads it through to the end. The files will be in the order they were added to the directory table.






share|improve this answer













Whatever it finds first. DIR in MS-DOS command.com starts at the beginning of the directory table and reads it through to the end. The files will be in the order they were added to the directory table.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 19 at 0:37









RETRACRETRAC

915411




915411








  • 1





    "The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

    – a CVn
    Apr 20 at 18:51














  • 1





    "The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

    – a CVn
    Apr 20 at 18:51








1




1





"The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

– a CVn
Apr 20 at 18:51





"The files will be in the order they were added to the directory table." If the other two answers are correct, that's not strictly true. Rather, the files would be in the order in which they exist in the directory entries list. Is that what you meant, or are you proposing an answer different from that of the other two currently existing answers?

– a CVn
Apr 20 at 18:51










TSJNachos117 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















TSJNachos117 is a new contributor. Be nice, and check out our Code of Conduct.













TSJNachos117 is a new contributor. Be nice, and check out our Code of Conduct.












TSJNachos117 is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Retrocomputing Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f9748%2fwhat-order-were-files-directories-output-in-dir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

Brian Clough

Cáceres