在我当前的 powershell 脚本中,我有包含值的哈希表。我使用这个语法
$x = $f.contains("$k")
Run Code Online (Sandbox Code Playgroud)
但我最近发现这种方法有问题,我想知道powershell是否有一些“开头为”或相关的内容,它会通过“开头为”而不是“开头”来搜索哈希表contains
哈希表的示例:
"bio.txt" = "server1\datafiles\bio";
etc.......
Run Code Online (Sandbox Code Playgroud)
编辑评论中的示例
foreach ($key in $filehash.keys) {
$path = $filehash.get_Item($key)
$filecount = 0
foreach ($file in $FileArray) {
if ($file.LastWriteTime -lt($(GetDate).adddays(-1))) {
[string] $k = $key.ToLower()
[string] $f = $file.name.ToLower()
if ($x = $f.contains("$k")) { }
}
}
}
Run Code Online (Sandbox Code Playgroud) 所以我在某个位置有文件夹
C:\Users\ainfowara\Desktop\testfiles
Run Code Online (Sandbox Code Playgroud)
所以我想将这些文件移动到这个位置
C:\Users\ainfowara\Desktop\destinationTestfiles
Run Code Online (Sandbox Code Playgroud)
"testfiles"有这种格式的文件,txt.*.test.*所以基本上我想在我移动文件之前检查它们在第三部分中有那两个主要的东西(txt)和(test).
有人可以帮助我,如何在powershell脚本中执行此操作
我知道我可以这样做,设置文件夹路径
path_src= C:\Users\ainfowara\Desktop\testfiles
path_dst= C:\Users\ainfowara\Desktop\destinationTestfiles
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助