Skip to content

CLI tool improperly recognizing directories #45

@GravlLift

Description

@GravlLift

When attempting to use command line tool on a directory with a . in the final folder level, the input is incorrectly assumed to be a file. For instance, C:/A.Directory is assumed to be a file, even if it's a folder name.

The root cause is a result of using a regex to determine filenames at:

public static bool EndsWithFileExtension(this string text)
=> Regex.IsMatch(text, @"\.\w+$");

I'd propose ditching the use of that extension method and just checking both file/directory existence at the same time.

So change the existing:

else if (command.Input.EndsWithFileExtension() && !File.Exists(command.Input))
{
return new ValidationResult($"The file path '{command.Input}' does not exist.");
}
else if (!command.Input.EndsWithFileExtension() && !Directory.Exists(command.Input))
{
return new ValidationResult($"The directory path '{command.Input}' does not exist.");
}

to simply:

else if (!File.Exists(command.Input) && !Directory.Exists(command.Input))
{
    return new ValidationResult($"The file or directory path '{command.Input}' does not exist.");
}

Might resolve #44?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions