当前位置: 移动技术网 > IT编程>脚本编程>Shell > PowerShell中文件对象的属性方法总结

PowerShell中文件对象的属性方法总结

2017年12月08日  | 移动技术网IT编程  | 我要评论

本文介绍一个powershell中文件对象有哪些属性,知道了这些属性对于我们更好的对文件进行操作是非常重要的。

powershell是一个面向对象的脚本语言,在powershell中,所有的都是对象,文件也是对象。既然是对象,那肯定有属性。powershell中的文件对象,其实就是.net中的system.io.fileinfo类的实例。我们要查看完整的powershell文件对象的属性,其实不需要去翻msdn,然后把system.io.fileinfo类的属性找出来,那样太麻烦了,而且貌似在powershell中,并不能完全按照.net框架中提供的信息来操作。

在这里,小编介绍给大家个一个很简单的获取文件对象属性的方法,那就是get-member。且看下面的示例:

复制代码 代码如下:

ps c:\users\splaybow> get-item d:\1.txt | get-member -membertype property

   typename: system.io.fileinfo

name              membertype definition
----              ---------- ----------
attributes        property   system.io.fileattributes attributes {get;set;}
creationtime      property   system.datetime creationtime {get;set;}
creationtimeutc   property   system.datetime creationtimeutc {get;set;}
directory         property   system.io.directoryinfo directory {get;}
directoryname     property   system.string directoryname {get;}
exists            property   system.boolean exists {get;}
extension         property   system.string extension {get;}
fullname          property   system.string fullname {get;}
isreadonly        property   system.boolean isreadonly {get;set;}
lastaccesstime    property   system.datetime lastaccesstime {get;set;}
lastaccesstimeutc property   system.datetime lastaccesstimeutc {get;set;}
lastwritetime     property   system.datetime lastwritetime {get;set;}
lastwritetimeutc  property   system.datetime lastwritetimeutc {get;set;}
length            property   system.int64 length {get;}
name              property   system.string name {get;}


在上面这个例子中,我们使用get-item获取到一个文件对象。然后在管道之后,使用get-member,把文件对象的所有属性全部都列了出来。其实这些属性都很好理解,大家一看属性名称就知道它表示文件的哪方面内容。

关于powershell中文件的属性,本文就介绍这么多,希望对您有所帮助,谢谢!   

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网