从当前目录获取子文件夹中文件的相对路径 [英] Get relative path of files in sub-folders from the current directory

查看:42
本文介绍了从当前目录获取子文件夹中文件的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何直接的方法(通过使用 cmdlet 或 .NET 类)仅从给定路径获取子文件夹中文件的相对路径?

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?

例如当前文件夹是 C:\MyScript 并且有一个名为 Data 的子文件夹,其中包含一个文件 Test.txt,所以我想看到 Data\Test.txt 而不是 C:\MyScript\Data\Test.txt

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 参数,该参数将返回相对于当前路径的路径目录:

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

这篇关于从当前目录获取子文件夹中文件的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆