2022-09-07 C# でフルパス判定

System.IO.Path.IsPathRooted()

すぐに触れる C# 環境が無いので .NET Framework 4.8 の Win10 PowerShell でテスト.\ から始まる文字列が True 判定されてしまう….

PS> [System.IO.Path]::IsPathRooted("path-string")
False
PS> [System.IO.Path]::IsPathRooted("\path-string")
True
PS> [System.IO.Path]::IsPathRooted(".\path-string")
False
PS> [System.IO.Path]::IsPathRooted("..\path-string")
False
PS> [System.IO.Path]::IsPathRooted("C:\path-string")
True
PS> [System.IO.Path]::IsPathRooted("\\path-string")
True

System.IO.Path.IsPathFullyQualified()

.NET 5 から使える.こちらだと \ から始まる文字列は False 判定になる.

ToDO

  • C# でコード例