【发布时间】:2022-10-03 04:02:57
【问题描述】:
我想构建一个对其他人也可能有用的简单脚本,但我只有非常基本的编程知识,如果不学习如何从头开始编写 powershell 脚本,我自己无法做到。
这个脚本应该做的是,打开一个 INI 文件(实际上只是一个 txt),查找具有分配值的变量,并从托管在 GitHub 上的 txt 中替换该值,保存然后运行程序。
这是用于 qBittorrent 的跟踪器列表,因为该功能尚未实现,而且我能找到的唯一其他脚本适用于 linux 和 mac,Windows 似乎没有。
基本思想是这样的:
get-content \"c:\\users\\[user]\\appdata\\roaming\\qbittorrent\\qbittorrent.ini\"
# This is where pseudo code starts
get file from \"[github-link.txt]\"
save file to cache # keeping it is useless as it gets updated daily
find variable \"Session\\AdditionalTrackers=\" in qbittorrent.ini
replace value of variable with content of cached file # this is what I struggle with most when looking for example code. Everything I could find specified the exact string that needed replacing, which in this case is quite long and may change with every update of the file.
overwrite original file
launch program qbittorrent.exe
end script
方便地或很可能是故意的,GitHub 上的所有(大多数)跟踪器列表已经格式化,可以直接粘贴到文件中,而不必担心格式化。 Example。
如果没有人愿意做这项工作,我完全可以理解,但我将不胜感激,可能还有其他人正在为缺乏的功能寻找权宜之计。
如果这已经存在,请继续称我为白痴,当你在它的时候放下一个链接;)
-
我建议将您的问题集中在您的核心问题上:更新 INI 文件中的值。最好提供示例文件内容和所需的输出,以及您到目前为止所尝试的内容。
标签: powershell