Wednesday, April 24, 2024
HomePowershellPowerShell: Cut up-Path Examples – SID-500.COM

PowerShell: Cut up-Path Examples – SID-500.COM


PowerShell

The cmdlet Cut up-Path could be helpful to separate volumes, folder and file path names. On this weblog posts I offers you some examples you possibly can construct on. Have enjoyable studying the code samples to study extra concerning the energy of Cut up-Path.

Code Samples

Please check with the next code pattern and its feedback.

# Cut up Paths
# Present file path
Cut up-Path $homedocumentstest.txt -Guardian               
# Present final factor
Cut up-Path $homedocumentstext.txt -Leaf                  
Cut up-Path $homedocuments -Leaf      
# Present Drive Letter                 
Cut up-Path $homedocumentstext.txt -Qualifier
# Path with out Drive Letter         
Cut up-Path $homedocumentstext.txt -NoQualifier   
# Resolve Identify (Present full path) 
Cut up-Path $homedocuments -Resolve                         

# Present Sub-Folder (dir3)
Cut up-Path (Cut up-Path c:dir1dir2dir3file.txt -Guardian) -Leaf    
# Present Sub-Folder (dir2)
Cut up-Path c:dir1dir2dir3file.txt -Guardian |                 
# Present Sub-Folder (dir2)
Cut up-Path c:dir1dir2dir3file.txt -Guardian | Cut up-Path -Leaf                             
# Or ...
('c:dir1dir2dir3file.txt' -split '')[2]
# Shows all phrase paperwork file names
Set-Location C:
Cut up-Path -Path .temp*.docx -Resolve -Leaf         
# Is that this an absolute path ?
Cut up-Path $homedocumentstext.txt -IsAbsolute         
Cut up-Path .Home windows -IsAbsolute                        

# Mixture 😉
(Cut up-Path C:Windowssystem32) + '' 
+ (Cut up-Path $homedocumentstest.txt -Leaf)

Hope this text was useful!

Revealed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2023], IT-Coach, IT-Advisor, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments