Bu1'Blog

如果能控制粗鄙的狂喜,就不会有深入骨髓的悲伤。

0%

powershell批量替换文件中的字段内容

通过powershell对原有的py文件字段进行更改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#获取目录下文件
$list = Get-ChildItem *.py
#初始的内容
$init_name = "name = `'"
$init_sev = "severity = `"`""
$ext_name = "漏洞"
$key = 1
foreach( $i in $list){
Write-host "No.$key..."
$name = $i.Name -replace ".py",""
$rep_name = "name = `'$name$ext_name`'"
$rep_name
$rep_sev = "severity = `"Medium`""
(type "$i" -Encoding utf8) -replace ("$init_name","$rep_name") | Out-File -encoding utf8 -FilePath "$name.py1"
(type "$name.py1" -Encoding utf8) -replace ("$init_sev","$rep_sev") | Out-File -encoding utf8 -FilePath "$name.py1"
$key++
}
#程序完成后改名
#Get-ChildItem | Rename-Item -NewName { $_.Name -replace "py1","py"}