我需要复制软件(HWMonitorPro)生成的图像。无法修改图像的文件夹和子文件夹(或者我没有找到方法)。
图像存储在以下路径中:C:\Users\hugo\Documents\DossierTest\logs\[JUN 13, 2022 - 11:06]\[LAPTOP-P15V]\[1280x960].
如您所见,每个记录都会创建一个包含日期和时间的目录。因此,我决定使用以下技术,以便能够同时拍摄多个捕获的图像:
$C = "C:\Users\hugo\Documents\DossierTest\logs"
copy-item $C'\*\`[LAPTOP-P15V`]\`[1280x960`]\789.txt' -Destination $C\test3这句话用的是“6月14日,2022-9:22”而不是"*“。当我使用上面的行显示时,我得到了这样的结果:
PS C:\Windows\system32> C:\Users\hugo\Documents\DossierTest\ScriptCC.ps1
Copy-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: [LAPTOP-P15V
At C:\Users\hugo\Documents\DossierTest\ScriptCC.ps1:3 char:1
+ copy-item $C'\*\`[LAPTOP-P15V`]\`[1280x960`]\789.txt' -Destination $C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Copy-Item], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.CopyItemCommand如果有人能帮我解决我的问题,那就太好了!
PS:我是法国人,如果写得不好,很抱歉。
发布于 2022-06-18 11:08:56
由于包含方括号的路径似乎有些奇怪,您可以使用CopyTo方法来复制文件,而不是复制项cmdlet。例如:
$rootfolder = "E:\tmp\logs"
$destfolder = "E:\tmp\foldertest3"
$allfiles = gci $rootfolder -File -Recurse
foreach ($file in $allfiles) {
$newfile = $file.CopyTo("$destfolder\$($file.Name)")
}这会将子目录中的所有文件复制到单个目标文件夹=,如果在不同的子文件夹中存在同名文件,则需要进一步处理t。
PS:在处理文件路径时,$C确实是一个糟糕的变量名:-)
https://stackoverflow.com/questions/72631746
复制相似问题