Batch file 用于删除和替换多个位置中的文件的批处理脚本
我想做的是创建一个批处理文件来替换用户应用程序数据文件夹中的cert8.db文件,并在其中一个prefs.js文件中插入一行文本。通常这很容易,问题是我的一些用户很可能有多个firefox配置文件,因此我希望有一个脚本来替换firefox/profiles文件夹中的所有cert8.db文件,并在firefox/profiles文件夹中的所有prefs.js文件中插入一行nextBatch file 用于删除和替换多个位置中的文件的批处理脚本,batch-file,vbscript,Batch File,Vbscript,我想做的是创建一个批处理文件来替换用户应用程序数据文件夹中的cert8.db文件,并在其中一个prefs.js文件中插入一行文本。通常这很容易,问题是我的一些用户很可能有多个firefox配置文件,因此我希望有一个脚本来替换firefox/profiles文件夹中的所有cert8.db文件,并在firefox/profiles文件夹中的所有prefs.js文件中插入一行next 这能做到吗?如果可能的话,我愿意使用vb。您可以这样做: Set fso = CreateObject("Script
这能做到吗?如果可能的话,我愿意使用vb。您可以这样做:
Set fso = CreateObject("Scripting.FileSystemObject")
profilesFolder = "C:\Users"
firefoxProfiles = "AppData\Roaming\Mozilla\Firefox\Profiles"
For Each fldr In fso.GetFolder(profilesFolder)
profilePath = fso.BuildPath(fldr.Path, firefoxAppdata)
If fso.FolderExists(profilePath) Then
For Each profile In fso.GetFolder(profilePath)
certdb = fso.BuildPath(profile, "cert8.db")
prefs = fso.BuildPath(profile, "prefs.js")
If fso.FileExists(certdb) Then
'replace cert8.db
End If
If fso.FileExists(prefs) Then
'modify prefs.js
End If
Next
End If
Next
替换DB文件和修改首选项的代码取决于替换DB的来源以及您希望在首选项中添加或更新的内容
FOR /D %%i IN (C:\Users\*.*) Do FOR /D %%j IN (%%i\AppData\Roaming\Mozilla\Firefox\Profiles\*.*) Do (
CALL :ReplaceDB "%%j\cert8.db"
CALL :ChangeJS "%%j\prefs.js"
)
:ReplaceDB
IF NOT EXIST %1 GOTO :EOF
MOVE /Y %1 "%~1.old"
COPY C:\firefox\cert8.db %1
GOTO :EOF
:ChangeJS
IF NOT EXIST %1 GOTO :EOF
ECHO user_pref("network.proxy.autoconfig_url", "pac.pe.lan/pac/proxy.pac") >> %1
GOTO :EOF
编辑:为搜索配置文件添加第二个。
编辑:添加了用于替换DB和将行追加到JS的代码。任务1是定位firefox配置文件存储位置。然后,如果未锁定cert8.db文件,则查找和替换它们很容易。prefs.js-您是否只想将文本添加到文件的末尾,而不管文件中还有其他内容?我插入了新代码:位于firefox配置文件下newcertfile=“C:\firefox\cert8.db”
如果fso.FileExists(certdb),那么objFSO.CopyFile“cert8.db”、“cert8.old”objFSO.CopyFile newcertfile,覆盖现有的
,除非将工作目录设置为配置文件文件夹,否则需要使用CopyFile
中的完整路径。此外,我还将使用MoveFile
重命名旧的cert8.db
,因此在第二步中不需要强制覆盖现有文件。另外,您的第二个CopyFile
只有源路径。您还需要一个目标路径。我做了调整,但它出错了:对于fso.GetFolder(profilesFolder)中的每个fldr,我将profilesFolder调整为`profilesFolder=“C:\users\%USERNAME%”,但它说路径不存在FileSystemObject
不展开环境变量,因此,如果不自己展开变量(var2=CreateObject(“WScript.Shell”).expandEnvironmentString(var1)
),就不能在路径中使用%USERNAME%
(或%USERPROFILE%
)之类的内容。这两个文件实际上位于profiles\somethingrandom\cert8.db和perfs.js中,我可以执行类似的操作“%%i\AppData\Roaming\Mozilla\Firefox\Profiles\*\cert8.db”?我这样做了,但是我知道文件正在复制到C:\,如何将它们放在(%%i\AppData\Roaming\Mozilla\Firefox\Profiles**)中?:ReplaceDB如果不存在%1转到:EOFREM在这里替换%1中的DB!重命名cert8.DB cert8.DB.old复制C:\firefox\cert8.DB cert8.DB转到:EOF如果不存在%1转到:EOFREM在这里更改%1中的JS!设置str1=%1设置str1设置str1=%str1:user pref(“network.proxy.config\url