The solution is very simple to use a command in PowerShell to check whether a file path or folder path is available!The solution is very simple with the test-path command, if you do not see the files in the standard Windows file explorer because it may be hidden or does not appear at all. Here is a solution that administrators on MS Windows 11, 10, ... MS Servers OS like to use to query the existence of certain folders, files and file types / file extensions! To do this, start the Windows Powershell , or optionally PowerShell in the ColorConsole ! EXAMPLE 1: Query whether a directory exists! The test-path -path command checks whether all elements are present in the path, ie the drive "C:\" and the main directory "Windows" and the subdirectory "System32" . PS C:\> test-path -path "C:\Windows\System32" True
PS C:\> test-path -path "C:\Windows\System64"
False
PS C:\>
If an element is missing, the test-path returns "False" as the return value. Otherwise "True" EXAMPLE 2: The layer command $ profile to test the path to the Windows PowerShell profile. And querying the profile file ;-) PS C \> test-path -path $profile -IsValid
True
PS C \>
PS C: \>$profile
C:\Users\Nenad\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\>
These commands use "$profile", the automatic variable that points to the location for the profile, even if the profile does not exist. EXAMPLE 3: With this command you can query certain file extensions whether they exist in the directory! PS C:\> test-path -path "C:\Windows\*.ini" -exclude *.txt
True
PS C:\> test-path -path "C:\Windows\*.ini2" -exclude *.txt2
False
PS C:\>
Further helpful tips: ► ... MS-Determines whether all elements of a path exist?FAQ 43: Updated on: 26 August 2023 10:26 |