![](/img/trans.png)
[英]Read a file and then based on file content names, move the file from one folder to another using Powershell script
[英]Powershell: Move file from one directory to another, based on string within file
环顾四周,似乎找不到自己的答案。
我正在寻找编写脚本,该脚本可让我根据文件中的内容将文件从一个目标移到另一个目标。
进入细节
源目标-V:\\ SW \\ FromSite复制到目标-V:\\ SW \\ ToSW文件类型-.txt字符串-测试
理想情况下,我也只希望有以7开头的脚本搜索文件。这些是区域的唯一标识符。
拉我的头发有点尝试。
我正在使用以下程序,该程序运行时没有错误,但没有执行任何操作。
$DestDir = "V:\SW\FromSite"
$SrcDir = "V:\SW\ToSW"
$SearchString = "test"
gci $SrcDir -filter 7*.txt | select-string $SearchString | select path |
move-item -dest $DestDir -whatif
这是我会做的,尽管我敢肯定还有一种更简化的方法。
$files = gci $SrcDir -filter 7*.txt
$files | %{
if ((select-string -path $_.FullName -pattern $SearchString) -ne $null) {
move-item -path $_.FullName -dest $DestDir
}
}
因此,还有些混乱了,以下内容可以完美满足我的需求
get-childitem "<SourceFolder>" -filter 7*.txt -
recurse | select-string -list -pattern "test" | move -dest "<DestinationFolder>"
谢谢大家的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.