小编ain*_*ara的帖子

在powershell脚本中使用“开头为”而不是包含?

在我当前的 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)

powershell hashtable

3
推荐指数
1
解决办法
2万
查看次数

在powershell脚本中将文件从一个位置复制到另一个位置,另外还要检查某些值

所以我在某个位置有文件夹

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)

在此先感谢您的帮助

directory powershell file

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

powershell ×2

directory ×1

file ×1

hashtable ×1