Bug: Hyphens in path to DeleteFiles can be misinterpreted as command switches!
Just noticed a fairly dangerous bug in the DeleteFiles utility, where if you're passing in the path to where the DeleteFiles.exe resides and that path contains hyphens, then they could be interpreted as command line switches by this function below:-
protected bool ParseParameterSwitch(string parm) {
int at = CommandLine.IndexOf(parm,0,StringComparison.OrdinalIgnoreCase);
if (at > -1) return true;
return false;
}
So for example, if I place DeleteFiles.exe in a folder called "C:\my-lol-utils" and call it by using the full path to DeleteFiles like this:-
C:\my-lol-utils\DeleteFiles c:\mystuff*. -d10
I would expect that to delete "mystuff" files over 10 days old. However, this doesn't happen because the folder "my-lol-utils" contains a hyphen followed by the letter L which is interpreted as "Display Mode" where it displays what would otherwise get deleted if that switch wasn't there, and so nothing gets actually deleted!
So not much harm there, but where it actually might get dangerous would be if I placed DeleteFiles.exe within a folder called "my-rofl-utils" and executed the same command again, e.g.
C:\my-rofl-utils\DeleteFiles c:\mystuff*. -d10
In this case, the "my-rofl-utils" contains a hyphen followed by the letter r which is interpreted as "Delete files [R]ecursively". Therefore rather than deleting old files just at the root of "mystuff" it would traverse every directory below "mystuff" as well deleting all the old files from each! This is totally unexpected!
The issue also happens where you prefix the filespec with a path, and that path also contains a hyphen. e.g.
DeleteFiles c:\my-reallygoodstuff*. -d10
The above statement would recursively delete all the files in and below "my-reallygoodstuff" again because the -r in the folder name is misinterpreted as a command switch for recursion!
At the very least, I think there should be a warning in the readme description warning about this situation.
While this is probably an edge case, it did in fact happen to me!