Z
Zhiguo
Hi, my friends:
I am using Scripting.FileSystemObject to read local files in
standalone .js application.
However, sometimes Scripting.FileSystemObject fails to read existing
files.
FileExists returns false when check file existence, and gets exception
if try to read file directly.
This happen when WPS restarts:
(1) WPS is a word processing software similar to MS Word, with similar
plugin platform also;
(2) My program is a plugin for WPS. The plugin calls a standalone .js
file with ShellExecute;
(3) The .js file read local files.
The strange thing is:
(1) when the WPS installs the plugin, the .js reads file ok.
(2) If restart WPS, the plugin again calls the .js file, then the
FileExists function of Scripting.FileSystemObject always fails.
(3) If unstall the plugin, and re-install the plugin, things are ok
again. If restart WPS, then FileExists fails again.
Why does this happen? And how to solve this problem?
Thanks in advance! Any help will be appreciated!
//here is my code:
function ReadAllContentFromFile(strFileName){
try{
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var vFileContent = "";
if (objFSO.FileExists(strFileName)){
var vFile = objFSO.OpenTextFile(strFileName, 1, false,0);
vFileContent = vFile.ReadAll();
vFile.Close();
}else{
vFileContent = "NOT EXIST: " + strFileName;
}
objFSO = null;
return vFileContent;
}catch(error){
return "EXCEPTION: " + error + "@" + strFileName;
}
}
I am using Scripting.FileSystemObject to read local files in
standalone .js application.
However, sometimes Scripting.FileSystemObject fails to read existing
files.
FileExists returns false when check file existence, and gets exception
if try to read file directly.
This happen when WPS restarts:
(1) WPS is a word processing software similar to MS Word, with similar
plugin platform also;
(2) My program is a plugin for WPS. The plugin calls a standalone .js
file with ShellExecute;
(3) The .js file read local files.
The strange thing is:
(1) when the WPS installs the plugin, the .js reads file ok.
(2) If restart WPS, the plugin again calls the .js file, then the
FileExists function of Scripting.FileSystemObject always fails.
(3) If unstall the plugin, and re-install the plugin, things are ok
again. If restart WPS, then FileExists fails again.
Why does this happen? And how to solve this problem?
Thanks in advance! Any help will be appreciated!
//here is my code:
function ReadAllContentFromFile(strFileName){
try{
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var vFileContent = "";
if (objFSO.FileExists(strFileName)){
var vFile = objFSO.OpenTextFile(strFileName, 1, false,0);
vFileContent = vFile.ReadAll();
vFile.Close();
}else{
vFileContent = "NOT EXIST: " + strFileName;
}
objFSO = null;
return vFileContent;
}catch(error){
return "EXCEPTION: " + error + "@" + strFileName;
}
}