powershell - Powershell查找文件夹/子文件夹,然后写入if条件以仅在文件夹A大于文件夹B时执行操作
问题描述
基本上需要写给我子目录列表的powershell。在我的子目录中,我的文件夹结构类似于 101.10.1 、 101.10.2 、 101.10.3 现在想写 if 条件从文件夹 (101.10.3) 中获取更高的目录并删除 ms sql 2005 应用程序。
像这样的东西
****$path = "C:\abc\xyzh\Versions"
$contents = Get-ChildItem -Path $path | sort | Select-Object -Last 10
$contents.Name
$condition = $contents.Name
if ( $condition -gt "$path/$condition" )
{
# do something"
}****
解决方案
假设你有:
101.10.1
101.10.2
101.10.211
101.10.3
101.10.323
101.10.4
101.10.5
101.10.610
如果您运行此命令:
gci | sort -property name | ?{$_.name -gt '101.10.3'} | %{ echo "dosomething $_" }
你得到:
dosomething 101.10.323
dosomething 101.10.4
dosomething 101.10.5
dosomething 101.10.610
现在,您可以将 echo "dosomething $_" 更改为另一个有用的命令。
推荐阅读
- android - 如何从项目刷新活动
() 班级? - python-3.x - openCV mobilenet SSD转发功能中的断言失败
- java - 如何比较两个给定字符串的最后 10 个字符?
- javascript - 路由控件名称并添加自定义标记
- java - Java:限制对复合类方法的访问(接口和组合)
- c# - 如何在邮寄标签水晶报表中复制标签?
- list - 为什么 `(read)` 值列表在 Scheme 中以相反的顺序出现?
- c# - 无法访问 MVC 控制器中 Web Api 控制器设置的 cookie
- sql - VB.Net 命令对象 SQL 查询返回 Null 或 0
- python - 保持套接字打开直到客户端终止