Using scripting.filesystemobject in javascript and checking for locked files
I have some code that reads from an ini file in Javascript,开发者_如何学编程 using activex filesystem objects.
This isn't particularly efficient but does the job, reading the whole file into an array, appending any changes and writing back.
The problem i'm having is that another process, a C# XBAP application is reading from this ini file (using getprivateprofilestring) at the same time as I could potentially be trying to write to it in the JS.
The javascript fails as the file is locked, or part of it, and the file ends up getting corrupted or even totally cleared - as I am trying to write back the whole file each time.
Preferably, what I need is a way to determine if a file is locked in javascript, as the writes are not urgent and I want to let any reads finish first.
Just can't seem to find anyway of syncing these two completely seperate ways of accessing the file.
May be you could use try/catch
. If you open the file for appending (OpenTextFile([filename],8
)) it should raise an exception. Same should be true for writing/saving the file (if the file is locked try
raises an exception).
精彩评论