从当前目录获取子文件夹中文件的相对路径(Get relative path of files in sub

编程入门 行业动态 更新时间:2024-10-26 08:35:07
从当前目录获取子文件夹中文件的相对路径(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 -Relative

The 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

更多推荐

本文发布于:2023-08-05 10:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   路径   目录   夹中   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!