PowerShell中使用Test-Path命令检查文件或文件夹路径是否存在示例
检查文件或文件夹路径是否存在,在编程中是经常用到的功能。powershell对于这个需求提供了一个非常便捷的cmdlet,那就是test-path!呵呵,看个名字,你就明白它有多么专业了。看看关于它的基本介绍先:
test-path,检查路径是否存在。
语法:test-path <路径>
说明:这里的路径可以是:文件、文件夹、hklm路径、环境变量env:路径
下面来举一些例子,让大家更方便懂:
test-path d:\q.txt
test-path c:\scripts\archive -pathtype container
test-path "hkcu:\software\microsoft\driver signing"
test-path alias:\gci
test-path env:\username
test-path c:\scripts\archive -pathtype leaf
test-path c:\scripts\archive\*.ps1
test-path c:\scripts\archive\* -include *.ps1, *.vbs
test-path c:\scripts\archive\* -include test*.ps1, test*.vbs
test-path c:\scripts\archive\* -exclude *.ps1
test-path c:\scripts\archive\* -exclude *.gif, *.jpg
test-path d:\网站备份\2013-04-*\cnsm* #检查2013-04开头的目录下有没有cnsm开头的项目
看完之后,冰雪聪明的你,是不是觉得这玩意儿太tm的强大了?唉,这是它为什么叫powershell的原因了。
说说返回值,test-path的返回值为true或false,所以,你可以把它放到if语句中,效果是非常好的。
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
-
Flink组件解析
1.什么是flink?Flink 是一个框架和分布式处理引擎,用于对无界和有界数据流进行有状态计算。Flink ...
[阅读全文]
-
-
-
-
架构设计步骤
业务为要,架构先行设计期系统分拆:如何把系统拆解成不同的子系统,模块和业务单元技术选型:选用什么样的基础,技术框...
[阅读全文]
网友评论