Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI tool improperly recognizing directories #45

Open
GravlLift opened this issue Jul 13, 2022 · 0 comments
Open

CLI tool improperly recognizing directories #45

GravlLift opened this issue Jul 13, 2022 · 0 comments

Comments

@GravlLift
Copy link

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?

@GravlLift GravlLift changed the title CLI tool improperly recognizing files CLI tool improperly recognizing directories Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant