can I use the classic Test-Path to check if exists into a specific folder a file with a specific word into its name?
for example, I want to check if exists a file that starts with the word "LAB". after that word there is the datestamp that I cannot calculate.
If you need only file name then use the -Leaf parameter. To retrieve the root directory, you need to use the -Qualifier parameter. PS C:\> Split-Path 'C:\Temp\PsExec.exe' -Qualifier C: If you want to check if the path is absolute or relative then use the -IsAbsolute Parameter.
Get-ChildItem cmdlet in PowerShell is used to get items in one or more specified locations. Using Get-ChildItem, you can find files. You can easily find files by name, and location, search file for string, or find file locations using a match pattern.
The Split-Path cmdlet returns only the specified part of a path, such as the parent folder, a subfolder, or a file name. It can also get items that are referenced by the split path and tell whether the path is relative or absolute. You can use this cmdlet to get or submit only a selected part of a path.
The Test-Path cmdlet determines whether all elements of the path exist. It returns $True if all elements exist and $False if any are missing. It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal or leaf element.
why not:
test-path c:\myfolder\lab* -pathtype leaf #leaf is for file (get-help test-path -full)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With