微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cmd和powershell中的负数

如何解决cmd和powershell中的负数

| 有没有办法在cmd或powershell中进行取反?换句话说,我要查找的是名称中所说的所有不满足特定条件的文件(将否定指定为“-”的属性除外)。如果存在也可以在其他情况下使用的通用否定则将很有帮助。此外,对于powershell,是否有一种方法可以获取文件名列表,然后将其存储为可以排序的数组等? 很抱歉要求提出如此基本的要求。     

解决方法

使用PowerShell,有许多方法可以否定一组条件,但是最好的方法取决于情况。在每种情况下使用单一否定方法有时可能效率很低。如果要返回不是DLL早于05/01/2011的所有项目,则可以运行:
#This will collect the files/directories to negate
$NotWanted = Get-ChildItem *.dll| Where-Object {$_.CreationTime -lt \'05/01/2011\'}
#This will negate the collection of items
Get-ChildItem | Where-Object {$NotWanted -notcontains $_}
由于通过管道的每个项目都将与另一组项目进行比较,因此效率可能非常低下。获得相同结果的更有效方法是:
Get-ChildItem | 
  Where-Object {($_.Name -notlike *.dll) -or ($_.CreationTime -ge \'05/01/2011\')}
正如@riknik所说,请查看:
get-help about_operators
get-help about_comparison_operators
此外,许多cmdlet都有一个“排除”参数。
# This returns items that do not begin with \"old\"
Get-ChildItem -Exclude Old*
要将结果存储在可以排序,过滤,重用等的数组中:
# Wrapping the command in \"@()\" ensures that an array is returned
# in the event that only one item is returned.
$NotOld = @(Get-ChildItem -Exclude Old*)

# Sort by name
$NotOld| Sort-Object
# Sort by LastWriteTime
$NotOld| Sort-Object LastWriteTime

# Index into the array
$NotOld[0]
    ,不确定我是否完全了解您的需求。也许是这样的东西(在PowerShell中)?
get-childitem | where-object { $_.name -notlike \"test*\" }
这将获取当前目录中的所有文件,这些文件的名称不以短语test开头。 要获取有关操作员的更多信息,请使用PowerShell的内置帮助:
get-help about_operators
get-help about_comparison_operators
    ,除了@riknik提到的内容外,对于Get-ChildItem和文件名的特定情况,您应使用ѭ7,这样会更有效。
Get-ChildItem c:\\scripts\\*.* -exclude *.txt,*.log
http://technet.microsoft.com/zh-CN/library/ee176841.aspx     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。