How do I get jscript code processing to run?
var a, ad, f, gf, so;
var so = new ActiveXObject("Scripting.FileSystemObject");
var gf = so.GetFolder(so.GetParentFolderName(WScript.ScriptFullName));
var adTypeBinary = 1;
var adTypeText = 2;
var adReadAll = -1;
var adReadLine = -2;
var adWriteChar = 0;
var adWriteLine = 1;
var adSaveCreateNotExist = 1;
var adSaveCreateOverWrite = 2;
var cwd = so.GetParentFolderName(WScript.ScriptFullName);
var wscPath = so.BuildPath(cwd, "vbsWrapperformoodle.wsc");
var vbs = GetObject("script:" + wscPath);
var InputBox = vbs.method_InputBox;
var strRepl;
var strWith;
strRepl = vbs.InputBox("Type letters before change.", "Inputbox");
if (!(strRepl)) {
WScript.Quit;
}
strWith = InputBox("Type letters after change", "Inputbox");
if (!(strWith)) {
WScript.Quit;
}
WScript.Echo(gf);
WScript.Echo(gf.Files.Count);
for (fileobj in gf.Files)
{
var sr = new ActiveXObject("ADODB.Stream");
sr.Type = adTypeText;
sr.charset = "utf-8";
sr.Open();
sr.LoadFromFile(fileobj);
var temp = sr.ReadText(adReadAll);
sr.Close();
var sw = new ActiveXObject("ADODB.Stream");
sw.Type = adTypeText;
sw.charset = "Shift_JIS"; sw.Open();
sw.WriteText(
temp.replace(new RegExp(strRepl, "g"), strWith)
,
adWriteLine
);
sw.SaveToFile(fileobj, adSaveCreateOverWrite);
sw.Close();
}
gf = "";
so = "";
WScript.Echo("Done.");
The for statement "for (fileobj in gf.Files){}"does not pass the process.
"WScript.Echo(gf. Files.Count);" displays the number of files in the folder and only the "Done" message is displayed.
Even if I try to change the code "for (fileobj in gf.Files)" like "for (gf.Files.Item in gf.Files)", it doesn't work. Can someone please tell me?
What I have tried:
I tried "gf.Files.Item" instead of "filename".
JScript doesn't have a "foreach" statement, so I don't think it's wrong in the form for(a in b){}.
But no success.
I'm in trouble because I don't have anyone around to ask.
Please help me.