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

Suggestion: File location default to current directory #53

Closed
askids opened this issue Jan 8, 2018 · 1 comment
Closed

Suggestion: File location default to current directory #53

askids opened this issue Jan 8, 2018 · 1 comment

Comments

@askids
Copy link

askids commented Jan 8, 2018

hi,

Had a question on FileArgument. When we use the FileArgument, do we always have to give the full path? With the FileMustExist condition set to true, the library will try to validate if file exists or not. In many cases, the file might be available in the same directory as the current executable for which the arguments are being passed. So I think that in such cases, it would be simpler to pick up the file from the current directory instead of always having to provide the full file path. This way, the size of the command line argument also can be shortened and can be kept less cluttered, when dealing with multiple arguments. Wherever needed, we can still continue to provide the full file path.

So similar to FileMustExist attribute, if we had similar attribute, say CheckCurDir, which the user can use to indicate if the file check must happen after considering the current directory path. So in such a case, we can first get the current execution directory and then try to see if File exists in current directory. If yes, then update the parsed argument value to full path after appending the directory. If the file is not found in current directory, then try verifying as if the given value is a full path.

Thanks!

@j-maly
Copy link
Owner

j-maly commented Jan 9, 2018

You don't have to use absolute paths.
What happens internally is something like this

var fi = new FileInfo(path);
if (FileMustExist && !fi.Exists)
{
  throw new FileNotFoundException
}

So the path handling & validation is done by FileInfo (.NET base class library object).

So if you don't use an absolute path, it will search in the current directory of your commandline session. That might be the same directory as where your executable is or not - depends on how you call it.

@j-maly j-maly closed this as completed Jul 12, 2018
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

2 participants