command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

`AcceptExistingOnly` for `FileInfo` accepts existing directories

Open Coryf88 opened this issue 1 month ago • 1 comments

Version 2.0.0 (Also affected 2.0.0-rc.2.25502.107, upgraded while creating issue)

A FileInfo argument/option with AcceptExistingOnly validation, considers an existing directory as valid.

Coryf88 avatar Nov 11 '25 14:11 Coryf88

I think it was broken by https://github.com/dotnet/command-line-api/pull/2077 which added the Directory.Exists check here:

https://github.com/dotnet/command-line-api/blob/e292617c0f829bfe777c7ad51467c6a509a9aff8/src/System.CommandLine/ArgumentValidation.cs#L187

Prior to that, it would only have used File.Exists.

KalleOlaviNiemitalo avatar Nov 11 '25 22:11 KalleOlaviNiemitalo