• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >PowerShell > PowerShell中把相对路径转换为绝对路径的2个方法

PowerShell中把相对路径转换为绝对路径的2个方法

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了powershell找不到路径,powershell 路径,powershell,windows powershell,powershell是什么等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在PowerShell中,有时候,我们需要把当前的相对路径解析为绝对路径,比如".\test.txt",我们想知道它的绝对路径的话,我们有两种方法可以实现。

1、有一个cmd-let,它叫Resolve-Path。

语法如下:
Resolve-Path <相对路径>
</div>

如果指定的相对路径的文件或文件夹,不存在,则将提示如下:
Resolve-Path : 找不到路径“C:\Users\zhanghong\test.txt”,因为该路径不存在。
所在位置 行:1 字符: 13
   + CategoryInfo          : ObjectNotFound: (C:\Users\zhanghong\test.txt:Str
  ing) [Resolve-Path], ItemNotFoundException
   + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Resol
  vePathCommand
</div> 
如果位置存在,则提示找到的路径:
Path
----
C:\Users\zhanghong\music
</div>

2、使用$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath方法

这个方法的好处是,不管这个相对路径的文件或文件夹存不存在,都可以顺利的它解析为绝对路径。

举例如下:
C:\Users\zhanghong\file.txt</div>
实际上,小编的这个C:\Users\zhanghong\file.txt文件是不存在的。

</div>

您可能想查找下面的文章:

  • Powershell使用C#实现缩写路径
  • PowerShell小技巧之查找获取注册表路径
  • PowerShell小技巧之观察UNC路径
  • PowerShell中把相对路径转换为绝对路径的2个方法
  • PowerShell中使用通配符匹配文件路径的例子

相关文章

  • Powershell小技巧之查找脚本中的函数
  • Windows 8 中的 PowerShell 3.0
  • PowerShell复制命令行历史命令方法
  • Powershell截取字符串并添加省略号的例子
  • Powershell改变脚本执行优先权的代码分享
  • PowerShell中按修改时间查找文件的方法
  • Windows Powershell 环境变量
  • Shell获取字符串长度的多种方法总结
  • PowerShell中编程清空IE缓存方法
  • PowerShell中常用的一些特殊运算符介绍

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Windows Powershell 环境变量
    • Windows Powershell 执行文件和脚本
    • Windows Powershell 定义函数
    • PowerShell入门教程之PowerShell管道介绍
    • PowerShell ISE自动化简单示例
    • Powershell小技巧之非相同域或信任域也能远程
    • PowerShell计算脚本执行时间的实现方法
    • PowerShell脚本反引号用法实例:随时随地给代码换行
    • Windows Powershell方法(对象能做什么)
    • PowerShell批量安装msi后辍软件的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有