Pregunta

Estoy tratando de arreglar un .hta que alguien de mi empresa creó hace 3 o 4 años. En este momento, si abre un archivo que otra persona ya ha abierto, perderá todo el trabajo que haya realizado y deberá volver a hacerlo manualmente. Así que estaba pensando simplemente en comprobar si el archivo ya está abierto y luego bloquear la edición o simplemente hacer una ventana emergente que dice "hey, si intentas guardar, te decepcionará". ¿Hay alguna manera fácil de verificar si el archivo ya está abierto en JavaScript?

El código para abrir el archivo es ...

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 + "'" );
        }

    }
}

y el código para LoadXMLDocument es ...

//-----------------------------------------------------------------------------
// 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 );
}
¿Fue útil?

Solución

Veo que esta es una publicación súper antigua, pero ¿por qué no usar VBS? Si se trata de una HTA, son compatibles con la ejecución conjunta:

objFSO = CreateObject("Scripting.FileSystemObject")

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

Otros consejos

De eso se trata control de revisión . No es diferente a otras formas del mismo problema que no involucra. archivos hta.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top