Powershell PS1获取儿童复制命令基本
我不是编码员。我有一个 Powershell 脚本 .ps1,它进入“db”的所有子文件夹并删除所有我想删除的文件。它适用于我需要的东西。代码如下:
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename00.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filename11.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*" -Include "filename11.dbc" -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename22.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\lnc\all" -Include filmename33.lnc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\edt\permanent" -Include filmename44.edt -Recurse | Remove-Item -Verbose
现在我想以通用的方式以相同的方式复制2个文件来模拟上面的代码,但我不知道该怎么做。
我正在使用此代码来复制文件:
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse
有人可以帮我创建 2 个通用代码(我认为每个副本一行),将“lnc\all”文件夹中的 2 个文件复制到“db”中现有的任何子文件夹中文件夹?
也就是说,用 2 个通用代码替换 6 个代码,以防“db”中还有其他文件夹,它也可以工作。谢谢。
我不是程序员,如果可能的话,请以现成的格式向我发送代码(作为示例,谢谢)
I'm not a coder. I have a Powershell script .ps1 that goes into all subfolders of "db" and deletes the files I want to delete in all of them. It works for what I need. The following code:
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename00.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filename11.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*" -Include "filename11.dbc" -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename22.dbc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\lnc\all" -Include filmename33.lnc -Recurse | Remove-Item -Verbose
Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\edt\permanent" -Include filmename44.edt -Recurse | Remove-Item -Verbose
Now I want to copy 2 files in the same way in a generic way to simulate this code above but I don't know how to do it.
I'm using this code to copy the files:
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse
Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse
Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse
Can someone help me create 2 generic codes (I think one line for each copy) to copy the 2 files inside the "lnc\all" folders to any subfolder existing in the "db" folder?
That is, replace the 6 codes with 2 generic ones, in case there are other folders in the "db" it works too. Thanks.
I'm not a programmer, if possible send me the code in ready format (as an example, thanks)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如注释中所述,对于代码的第一部分,除了具有参考之外,没有自动化的方法( hash表在这种情况下),以定位目录及其特定文件。哈希表的键是目标路径,而 values 是用
include
参数来定位的文件:对于第二个代码,它可以通过这种方式自动化,请注意,
-path
来自copy-item
的参数可以采取一系列路径来复制,因为我们正在复制相同的2个文件,您可以将两者的路径存储在变量中。然后,对于目标路径,似乎应该这样做:首先将所有目录在该路径中获取,每个目录将文件复制到它们:
For the first part of your code, as explained in comments, there is no automated way to do it aside from having a reference (hash table in this case) to target the directories and it's specific files. The keys of the hash table are the target paths and the values are the files to target with the
-Include
parameter:For the second code, it could be automated this way, note that the
-Path
parameter fromCopy-Item
can take an array of paths to copy, in that sense, since we're copying the same 2 files, you can store the paths of both in a variable. Then for the destination path, seems like this should do it:First get all the directories in that path, and the for each directory copy the files to them: