Wednesday 7 September 2022

the dot...

I was trying and catching stuff to create some basic logger for a program, and I thought of keeping some maximal number of log files, like 5 or so, in a separate directory. There is almost no danger that someone else would write anything there, but I added a filter: read all the files whose names contain "Log" and their extension is "txt". And got no results even though the files matching these criteria existed and the directory path was correct... 

...Well, it turns out that the dot is important here, some clever-whoever insisted that the System.IO.FileInfo.Extension should contain the leading dot. Why? I can't figure it out yet. Is it because it is easier to say

int lastDotIndex = FileInfo.Name.LastIndexOf(".");
string ext = FileInfo.Name.Substring(lastDotIndex);

rather than 

string[] splitWithRespectToDot = FileInfo.Name.Split('.'); 
string ext = splitWithRespectToDot.Last();

? Nice one. Especially with files whose names start with ".", but that's not my case. Yet.

It's not a bug, it's a feature.

No comments:

Post a Comment