OT: Sort directory *entries*

Hi,

Is there an established/built-in mechanism to reorder the dirent structs on Windows filesystems? Or, is it cheaper for me just to write a script to "coerce" things into the desired order?

Reply to
Don Y
Loading thread data ...

I take it you mean actually /change/ the order of the directory entries, rather than just make them look sorted.

As far as I know, their is unlikely to be a way to do it for NTFS as the filesystem uses a B-Tree which does not track the order. So even if you individually copy files one-by-one into an NTFS directory, you will not get any particular order within the directory structures - adding a file could cause the B-Tree nodes to split with different divisions of the files.

For FAT (and FAT32), it's a different matter - files are kept in a flat list in the directory structure, with an order than can easily be seen. Some devices (such as many MP3 players) handle files in that order.

There are probably utilities for Windows that can re-order the entries. On Linux, there is "fatsort" which is often used for ordering files on USB sticks for music players.

Reply to
David Brown

On Fri, 07 Aug 2015 10:06:00 +0200, David Brown Gave us:

If you use a GPT initialization of the drive, you are no longer tied down in the max number of partitions you can create as with MSDOS initialized drives, so one could try some creative set-ups utilizing a large number of small partitions.

I know this has nothing to do with the actual question you asked, but it is something to consider as a data storage scheme formation in one's modern thinking world.

Reply to
DecadentLinuxUserNumeroUno

Yes. Edit the directory itself.

Sorry, I should have mentioned FAT32.

I just hacked together a quick shell script to sort the "names" based on the criteria of interest, then moved them into a virgin directory. Done.

I was hoping there might have just been some magic incantation to do this

*for* me (e.g., Norton Utilities used to have this capability many aeons ago).

Thx!

--don

Reply to
Don Y

So how to do "see" the native order of the files in the directory via Windows. Mark

Reply to
makolber

You don't care what the a priori order is under windows. Rather, you "know" what the order *will* be when you recreate (move) the files into a virgin directory.

Reply to
Don Y

at

n.

s.

n

indows.

Allow me to clarify my question...

I know windows displays the entry order sorted per hoe you click the column headers...

My question is how do I then "see" the actual order that you have been disc ussing.

You are right, I don't care what the actual order is when simply looking at the directory on a PC, but I do care becasue I will be copying the directo ry to an MP3 player. (which seems to play the files in some order that does not correspond to the windows display)

So I can I determine (and edit) the directory entry order via windows?

Mark

Reply to
makolber

In my case, I'm actually looking at a DOS box "directory listing". But, I take your meaning...

AFAICT, you can't. Years ago, you could. But, MS keeps dicking with the user interface. E.g., "File 9" precedes "File 10" in the listing (which makes life easy for "commoners"... but is counterintuitive for anyone with any "experience")

The MP3 player doesn't do a L-R alpha sort on names? I.e., wouldn't "01 - First Song" automatically be played before "02 - Another Song"?

AFAICT, you can't see the order that the entries are stored in the directory. OTOH, you can simply copy them into another folder in the order that you would like them to appear -- based on whatever criteria you deem appropriate (file name, size, time of modification, reverse alpha by third letter of file name, etc.). You won't be able to *verify* this (on the PC) but you will "know it".

You *may* be able to "Select All" and copy to another folder and notice the order in which the files are copied. ISTR that Windows doesn't sort them by any criteria when doing this "en masse".

Reply to
Don Y

What, exactly is 'native order'? There are dozens of folks living on my block, they could be ordered by height, weight, street number, surname (alphabetically), age, shoe size... Native order isn't a well-defined attribute in a filesystem.

Reply to
whit3rd

I suppose you could always drop to console mode and do a Dir folderName \*.* > foldername\filename.txt.

Look at it in notepad.. etc..

Something like that..

If you were a programmer it could be simple actually..

FindFirst(*.*), FindNext etc...

Jamie

Reply to
M Philbrook

If readdir() (or equivalent) always returns the filenames in a specific order, that's the "native" order, i.e. the order in which programs which traverse a directory will process the files.

Reply to
Nobody

no order is specified in the readdir documentation.

--
  \_(?)_
Reply to
Jasen Betts

May i assume you are familiar with what is available (sort by name, by size, by type, by date)? What do you want for "order"?

Reply to
Robert Baer

If NTFS, you don't.

Reply to
Robert Baer

NOT if that is NTFS.

Reply to
Robert Baer

*Every* filesystem creates files and adds them to their "folders" in a predictable fashion. *You* just may not be able to internalize that ordering! There's no "random number" code built into a creat() call that causes a file to be placed in one spot "today" and another spot "tomorrow" -- all else being equal. What is important is the order in which objects (files) are added to the structure (whether that is the MFT or a "disk block" that encodes a folder structure). [If these algorithms weren't deterministic, all bets would be off and there'd be no advantage to using one particular structure over any other RANDOM structure!]
Reply to
Don Y

Try

DIR /O-N

The default is DIR /ON i.e. sort by name) and the "-" reverses that selection.

Even on NTFS, the files are listed in more or less random order, _not_ sorted by name, extension, creation time, size as I can see. So that might be the "natural" order.

To be certain, you would have to open the actual directory file in a hex editor and look for file names in UTF-16 (or is it UCS2), for Latin scripts, every other byte is null.

Reply to
upsidedown

On Fri, 07 Aug 2015 22:04:26 -0700, Robert Baer Gave us:

He is not referring to a file browser's view settings, idiot. He is talking about physical placement of the files and directories on the volume itself.

Your file browser does no such thing.

Reply to
DecadentLinuxUserNumeroUno

Open a command prompt, go to the directory, and type "dir" without any ordering switches (and without any DIRCMD environment variable). That should show the files in natural order.

Unless, of course, MS has fiddled with it in later versions of Windows...

Reply to
David Brown

Well, "apt-get install fatsort" then "fatsort" is almost exactly the magic you are looking for - except it is for Linux (and possibly *BSD). I expect these sorts of things are a lot easier on Linux than Windows

- in particular, it's easy for a program on Linux to access an unmounted filesystems, while Windows insists on mounting filesystems which makes direct access much harder.

On the other hand, Linux's caching layers make it harder to use a solution like the one you used. On Windows, the system treats the USB drive as completely dumb - and also treats the user as completely dumb. It assumes that you might pull the drive out at any moment, and therefore updates the directory and FAT continuously during a copy in order to keep these structures as current as possible. Therefore as long as you copy the files into the drive in the desired order, they will have that order in the directory structure. Linux caches metadata accesses, so the copies will be handled much faster (at least the metadata parts), but the ordering in the structures is less predictable unless your script does a "sync" between each copy.

Reply to
David Brown

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.