Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 在powershell脚本中将文件从一个位置复制到另一个位置,并检查某些值_File_Powershell_Directory - Fatal编程技术网

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

File 在powershell脚本中将文件从一个位置复制到另一个位置,并检查某些值,file,powershell,directory,File,Powershell,Directory,所以我有一个文件夹,里面有文件,在某个位置 C:\Users\ainfowara\Desktop\testfiles 所以我想把这些文件移到这个位置 C:\Users\ainfowara\Desktop\destinationTestfiles testfiles有这种格式的文件txt.*.test.*所以基本上我想在移动文件之前检查一下,在第三部分中他们有两个主要的东西txt和test 有人能帮我吗?如何在powershell脚本中执行此操作 我知道我可以这样做,设置文件夹路径 path_

所以我有一个文件夹,里面有文件,在某个位置

C:\Users\ainfowara\Desktop\testfiles
所以我想把这些文件移到这个位置

C:\Users\ainfowara\Desktop\destinationTestfiles
testfiles有这种格式的文件txt.*.test.*所以基本上我想在移动文件之前检查一下,在第三部分中他们有两个主要的东西txt和test

有人能帮我吗?如何在powershell脚本中执行此操作

我知道我可以这样做,设置文件夹路径

path_src= C:\Users\ainfowara\Desktop\testfiles
path_dst= C:\Users\ainfowara\Desktop\destinationTestfiles

提前感谢您的帮助

如果TestFiles中没有至少需要文件的子文件夹,请尝试以下操作:

$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" | Move-Item -Destination $dst -Force
$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" -Recurse | % {
    #Creates an empty file at the destination to make sure that subfolders exists
    New-Item -Path $_.FullName.Replace($src,$dst) -ItemType File -Force
    Move-Item -Path $_.FullName -Destination $_.FullName.Replace($src,$dst) -Force
}
如果源路径的子文件夹中有文件,请尝试以下操作:

$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" | Move-Item -Destination $dst -Force
$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" -Recurse | % {
    #Creates an empty file at the destination to make sure that subfolders exists
    New-Item -Path $_.FullName.Replace($src,$dst) -ItemType File -Force
    Move-Item -Path $_.FullName -Destination $_.FullName.Replace($src,$dst) -Force
}

请注意,如果文件名包含方括号[],则需要另一个名为PS bug的脚本。

如果testfiles中没有至少需要文件的子文件夹,请尝试以下操作:

$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" | Move-Item -Destination $dst -Force
$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" -Recurse | % {
    #Creates an empty file at the destination to make sure that subfolders exists
    New-Item -Path $_.FullName.Replace($src,$dst) -ItemType File -Force
    Move-Item -Path $_.FullName -Destination $_.FullName.Replace($src,$dst) -Force
}
如果源路径的子文件夹中有文件,请尝试以下操作:

$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" | Move-Item -Destination $dst -Force
$src = "C:\Users\ainfowara\Desktop\testfiles"
$dst = "C:\Users\ainfowara\Desktop\destinationTestfiles"

Get-ChildItem $src -Filter "txt.*.test.*" -Recurse | % {
    #Creates an empty file at the destination to make sure that subfolders exists
    New-Item -Path $_.FullName.Replace($src,$dst) -ItemType File -Force
    Move-Item -Path $_.FullName -Destination $_.FullName.Replace($src,$dst) -Force
}

请注意,如果文件名包含方括号[],则需要另一个名为PS bug的脚本。

。。。第三部分。第三部分是什么?你是说文件名是txt.something.test.something吗?或者里面的内容是这样的?如果是文件名:最后一个是扩展名还是txt.something.test.something.extension?txt.something.test.something.extension它可能以任何内容结尾,第二个内容之后可能是日期,然后是扩展格式,没有特定的内容。。。第三部分。第三部分是什么?你是说文件名是txt.something.test.something吗?或者里面的内容是这样的?如果是文件名:最后一个是扩展名还是txt.something.test.something.extension?txt.something.test.something.extension它可能以任何内容结尾,第二个内容之后可能是日期,然后是扩展格式,没有具体的内容这给了我错误,它为子文件夹创建了空文件,但从未将其更改为文件夹并复制到文件夹内容上。这起到了相反的作用:$sourceRoot=C:\temp$destinationRoot=C:\n Copy Item-Path$sourceRoot-Filter*.txt-Recurse-destinationRoot-container这给了我错误,它为子文件夹创建了空文件,但从未将其更改为文件夹并复制到文件夹内容上。相反,这起到了作用:$sourceRoot=C:\temp$destinationRoot=C:\n复制项-Path$sourceRoot-Filter*.txt-Recurse-destinationRoot-Container