tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Directory.GetFiles moral

9 Jan 2010 .NET, Programming in general

Oh yes. I have here another moral. And it’s not good for me, because it’s (again) described in documentation (but who reads it when there’s nice IntelliSense?). In my program ID3 renamer I have couple of custom IO operations. One of fundamental methods is for enumerating directory(ies) for all MP3 files. It’s based on Directory.GetFiles and few functions inside ID3 renamer need exact order of files. One of these functions is FreeDB search. When I was renaming files on my network share, it wasn’t finding anything. But when moving the directory to local drive everything was fine.

After some debugging I found, that the ordering of files from network share is different than from local drive. If you look to documentation you see:

The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.

Ahh, there’s your problem. :) Sadly enough, the ordering from local drive looks stable and it’s based on filename as expected. Thus in a lot of cases you’ll not smell that something may go wrong. But on non local drives (for me my NAS) you’ll hit this immediately.

Never mind, could be worse (my first shot was some bug in my “MP3File” class and that will be really bad, as it could break users’ files). This can be fixed easily.