Path
Resolve Path
-Path(0, pv): expand path containing special characters like~or UNC(Universal Naming Convention) path and some other special pathsps1Resolve-Path '~/*' # returns all PathInfo of children under `~` Resolve-Path ~ # returns expanded path as PathInfo of `~`1
2-Relative(switch): get all relative paths from current path or specified location of items to be listedps1Resolve-Path '~/*' -Relative # list all relative string of children under ~ relative to current location1-RelativeBasePath: get all relative paths from specified location of items to be listedps1Resolve-Path '~/*' -RelativeBasePath ~ -Relative # list all children of ~ relative to ~ itself1
Part of Path
-Path(0, pv): get parent path asstringps1Split-Path ([System.IO.Path]::GetTempFileName()) # C:\Users\username\AppData\Local\Temp1-Parent(!, switch): optional, the default flag forSplit-Path, returns the parent container of-Path-Leaf(switch): get base name of a pathps1Split-Path ([System.IO.Path]::GetTempFileName()) -Leaf # tmpfigvir.tmp1-LeafBase(switch): get base name without extensionps1Split-Path ([System.IO.Path]::GetTempFileName()) -LeafBase # tmpfigvir1-Extension(switch): get extensionps1Split-Path ([System.IO.Path]::GetTempFileName()) -Extension # .tmp1-Qualifier(switch): get drive prefix of the path, not available on non-Windows platformps1Split-Path ([System.IO.Path]::GetTempFileName()) -Qualifier # C:1-NoQualifier(switch): exclude the drive prefix of the path, not available on non-Windows platformps1Split-Path ([System.IO.Path]::GetTempFileName()) -NoQualifier # \Users\username\AppData\Local\Temp\tmpoo33lr.tmp1-IsAbsolute(switch): telling whether the path is absolute-Resolve(switch): handles relative or wildcard path for-Pathps1Split-Path ~/* -Resolve # all parents of children under ~, which are all the same as `Resolve-Path ~`1
Path Validation
-Path(0, pv): telling whether the path exists, can be relativeps1Test-Path '~/.vimrc' Test-Path '../.gitignore'1
2-Filter: common filterps1Test-Path '~/*rc'1-IsValid(switch): telling whether the provided path has correct syntaxps1Test-Path 'foo/bar' # False Test-Path 'foo/bar' -IsValid # True1
2-Exclude&-Include: telling whether any/no path matches the specified patternps1Test-Path '~/*' -Exclude *rc # is there any file exists besides rc files?1-PathType: telling whether the path is a leaf or a container(leaf is the child of a container)ps1Test-Path '~/.vimrc' -PathType Leaf # True, it is a file indeed1NOTE
The meaning of
Leafis not the same asLeafinSplit-Path,Leafcan be any kind of child of a container inSplit-Path.-NewerThan&-OlderThan: telling whether the path was created before/after a date(can be date string)ps1Test-Path ~/.vimrc -NewerThan "2012.6.12"1
Join Path
-Path(0)&-ChildPath(1): join one or more parents with single childps1Join-Path C:, D: foo # C:\foo # D:\foo1
2
3-AdditionalChildPath(remain): accepts unlimited count of child pathsps1Join-Path -Path foo -ChildPath foo -AdditionalChildPath foo, foo, foo # this is how it work formally Join-Path foo foo foo foo foo # this is how you could use it in daily life # foo\foo\foo\foo\foo1
2
3-Resolve(switch): resolve( and validate) the path and join them, supports wildcard to join multiple matches at one timeps1Join-Path ~/Projects nix-config -Resolve # C:\Users\username\Projects\nix-config Join-Path ~/Projects .git -Resolve # C:\Users\username\Projects\.git does not exist # Join-Path ~/Projects * -Resolve # equvalent to `Resolve-Path ~/Projects/* | % Path` #1
2
3