Powershell - Test the presence of file or folder with Test-Path
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!
Hello,
The -PathType argument to Test-Path allows us to check whether the item is a file or a folder
$folder = 'c:\windows'$file = 'notepad.exe'
# Demonstration for a folder -PathType Container :Test-Path -Path $folder -PathType ContainerTest-Path -Path $folder -PathType LeafTest-Path -Path "$dossier\$fichier" -PathType anyTest-Path -Path "$folder$file" -PathType any
# Demonstration for a -PathType Leaf file :Test-Path -Path "$folder$file" -PathType ContainerTest-Path -Path "$folder$file" -PathType LeafTest-Path -Path "$dossier\$fichier" -PathType anyTest-Path -Path "$dossier\$fichier"
Related links
Powershell - Simply send objects to different variables
Powershell - Tip - Simply send objects to different variablesPowershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfaces