Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell How to use test-path knowing only a part of filename

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.

like image 348
rschirin Avatar asked Apr 12 '13 12:04

rschirin


People also ask

How do you split a path in PowerShell?

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.

How do I find a specific file in PowerShell?

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.

How do you split paths?

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.

How do I check the path in PowerShell?

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.


1 Answers

why not:

test-path c:\myfolder\lab* -pathtype leaf #leaf is for file (get-help test-path -full)
like image 141
CB. Avatar answered Nov 03 '22 01:11

CB.