문제

저는 회사의 누군가가 3 ~ 4 년 전에 창조 한 .hta를 고치려고 노력하고 있습니다. 지금 당장 다른 사람이 이미 열려있는 파일을 열면 작업을 수행 한 작업을 잃어 버리고 수동으로 다시 수행해야합니다. 그래서 나는 파일이 이미 열려 있는지 확인한 다음 편집 잠금인지 또는 "이봐, 저장하려고하면 실망 할 것"이라는 팝업을 확인하기 위해 확인하고있었습니다. 파일이 이미 JavaScript에서 열려 있는지 확인하는 쉬운 방법이 있습니까?

파일을 여는 코드는 ...

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 );
}
도움이 되었습니까?

해결책

나는 이것이 슈퍼 오래된 게시물이지만 VBS를 사용하지 않는 이유는 무엇입니까? HTA라면 함께 달리는 것이 지원됩니다.

objFSO = CreateObject("Scripting.FileSystemObject")

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

다른 팁

그게 뭐야 개정 제어 모든 것입니다. 포함되지 않은 동일한 문제의 다른 형태와 다르지 않습니다. HTA 파일.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top