Check if a file exists or not in Windows PowerShell?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Check if a file exists or not in Windows PowerShell?

Message par ForumBot »

Check if a file exists or not in Windows PowerShell?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Check if a file exists or not in Windows PowerShell?

Message par ForumBot »

Just to offer [the alternative](https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx) to the [`Test-Path` cmdlet](https://technet.microsoft.com/en-us/library/ee177015.aspx) (since nobody mentioned it):

```
[System.IO.File]::Exists($path)

```

Does (almost) the same thing as

```
Test-Path $path -PathType Leaf

```

except no support for wildcard characters
Répondre

Revenir à « PowerShell »