0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| |
var oFileSys = new ActiveXObject("Scripting.FileSystemObject");
var oShell = new ActiveXObject("WScript.Shell");
var oVbScript = new ActiveXObject("ScriptControl");
function VbsInputBox(sMessage, sTitle, sDefault){
oVbScript.Language = "VBScript";
oVbScript.AddCode("Function InputBox2(sMessage, sTitle, sDefault) InputBox2 = InputBox(sMessage, sTitle, sDefault) End Function");
var sResult = oVbScript.Run("InputBox2", sMessage, sTitle, sDefault);
return sResult;
}
Main();
function Main(){
Editor.SelectAll(0);
var sAllText = Editor.GetSelectedString();
if(sAllText.indexOf("□検索条件") < 0){
oShell.Popup("Grepを先に実行してください。", 0 , "MultiRepExp");
return;
}
var aRegExp = new Array();
while(true){
var sSearch = VbsInputBox("検索するテキストを入力してください。\n(空欄で次へ進む)", "MultiRepExp", "");
if(sSearch == null) return;
if(sSearch == "") break;
var sTransfer = VbsInputBox("置換後のテキストを入力してください。", "MultiRepExp", sSearch);
if(sTransfer == null) return;
var oRegExp = new RegExp(sSearch, "gm");
oRegExp.sBefore = sSearch;
oRegExp.sAfter = sTransfer;
aRegExp.push(oRegExp);
}
if(aRegExp.length == 0){
return;
}
var sMessage = "置換しますか?\n";
for(var nLoop = 0; nLoop < aRegExp.length; nLoop++){
sMessage += "置換前:" + aRegExp[nLoop].sBefore + "\n";
sMessage += "置換後:" + aRegExp[nLoop].sAfter + "\n";
}
if(oShell.Popup(sMessage, 0 , "MultiRepExp", 1) != 1){
return;
}
var aSearchPath = new Array();
sAllText = sAllText.substr(sAllText.indexOf("□検索条件"));
sAllText = sAllText.substr(sAllText.indexOf("\r\n\r\n"));
var aAllTextLine = sAllText.split("\r\n");
var oPathCheck = new ActiveXObject("Scripting.Dictionary");
for(var nLoop3 = 0; nLoop3 < aAllTextLine.length; nLoop3++){
var sLine = aAllTextLine[nLoop3];
if(sLine.indexOf(" [") >= 0){
sLine = sLine.substr(0, sLine.indexOf(" [") + 2);
sLine = sLine.substr(0, sLine.lastIndexOf(((sLine.indexOf(") ") >= 0)? "(": " ")));
if(oFileSys.FileExists(sLine) && !oPathCheck(sLine)){
oPathCheck(sLine) = true;
aSearchPath.push(sLine);
}
}
}
for(var nLoop = 0; nLoop < aSearchPath.length; nLoop++){
var sPath = aSearchPath[nLoop];
try{
var oFile = oFileSys.OpenTextFile(sPath, 1);
if(oFile.AtEndOfStream){
oFile.Close();
continue;
}
}
catch(excep){
oShell.Popup("読み込みエラーです。\n" + sPath + "\n" + excep, 0 , "MultiRepExp");
return;
}
var sText = oFile.ReadAll();
oFile.Close();
for(var nLoop4 = 0; nLoop4 < aRegExp.length; nLoop4++){
var sText = sText.replace(aRegExp[nLoop4], aRegExp[nLoop4].sAfter);
}
try{
var oDestFile = oFileSys.CreateTextFile(sPath, true)
oDestFile.Write(sText)
oDestFile.Close();
}
catch(excep){
oShell.Popup("書き込みエラーです。\n" + sPath + "\n" + excep, 0 , "MultiRepExp");
return;
}
}
oShell.Popup("正常終了しました。", 0 , "MultiRepExp");
}
|