2009-06-17 70 views
0

我正在尝试修复某人在我的公司创建的3到4年前.hta。现在,如果您打开某个其他人已经打开的文件,您将失去已完成的任何工作,并且必须手动重新执行。所以我只是想检查一下,看看这个文件是否已经打开,然后锁定编辑,或者只是弹出一个说:“嘿,如果你试图拯救你会失望”。有没有简单的方法来检查该文件是否已经在JavaScript中打开?检测文件是否已在javascript/hta中打开

打开该文件的代码是...

function FileOpen(strSetup) 
{ 
    if(! strSetup) 
    { 
     strSetup = ShowDialog("choose-setup", {"DialogTitle" : "Load Setup"}); 
    } 

    if(strSetup) 
    { 
     if(FileSystem.FileExists(App.Paths.Configs + "/" + strSetup + ".setup")) 
     { 
      var fFile = FileSystem.GetFile(App.Paths.Configs + "/" + strSetup + ".setup"); 
      App.Config = LoadXMLDocument(fFile.Path); 
      // SaveCurrentConfig(); 
      RefreshView("setup-summary"); 
     } 
     else 
     { 
      alert("Could not find setup '" + strSetup + "'"); 
     } 

    } 
} 

和LoadXMLDocument代码...

//----------------------------------------------------------------------------- 
// FUNCTION : LoadXMLDocument - Loads an XML document 
// params : strPath - the path/file of the document to load 
//   : bCritical- if set true, we die if the document doesn't load 
// returns : an XML dom object on success, false otherwise 
//----------------------------------------------------------------------------- 

function LoadXMLDocument(strPath, bCritical) 
{ 
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); 
    xmlDoc.setProperty("SelectionLanguage", "XPath"); 
    if(! FileSystem.FileExists(strPath)) 
    { 
     Error("'" + strPath + "' is not a valid file path"); 
     if(bCritical) Abort(); 
     return(false); 
    } 
    var fFile = FileSystem.GetFile(strPath); 
    xmlDoc.load(fFile.Path); 
    if(xmlDoc.documentElement == null) 
    { 
     Error("Could not load XML document '" + fFile.Path + "'"); 
     if(bCritical) Abort(); 
     return(false); 
    } 
    return(xmlDoc); 
} 

回答

0

我看到这是超级旧的帖子,但为什么不使用VBS?如果是HTA,他们支持一起跑步:

objFSO = CreateObject("Scripting.FileSystemObject") 

strFilePath = "C:\test.txt" 
If objFSO.FileExist(strFilePath) Then 
    MsgBox "I win" 
End If 
1

这就是revision control是怎么一回事。这与没有涉及的同一问题的其他形式没有区别。 hta文件。