从当前目录获取子文件夹中文件的相对路径(Get relative path of files in sub-folders from the current directory)
是否有任何直接的方法(通过使用cmdlet或.NET类)从给定路径获取子文件夹中文件的相对路径?
例如当前文件夹是C:\ MyScript,并且有一个名为“Data”的子文件夹,并带有一个“Test.txt”文件,所以我想看到Data \ Test.txt而不是C:\ MyScript \ Data \ Test。文本
Is there any straight-forward way (by use of cmdlets or .NET classes) to obtain only the relative path of a file in a sub-folder from a given path?
eg current folder is C:\MyScript and there is a sub-folder called Data with a file Test.txt, so I would like to see Data\Test.txt instead of C:\MyScript\Data\Test.txt
最满意答案
Resolve-Path cmdlet具有-Relative参数,该参数将返回相对于当前目录的路径:
Set-Location C:\MyScript $relativePath = Get-Item Data\Test.txt | Resolve-Path -RelativeThe Resolve-Path cmdlet has a -Relative parameter that will return a path relative to the current directory:
Set-Location C:\MyScript $relativePath = Get-Item Data\Test.txt | Resolve-Path -Relative更多推荐
发布评论