الكشف عن إذا كان ملف مفتوح بالفعل في جافا سكريبت / HTA
-
05-07-2019 - |
سؤال
وأحاول إصلاح و .hta أن شخصا ما في الشركة التي أعمل بها خلقت قبل 3 أو 4 سنوات. الآن إذا قمت بفتح ملف شخص آخر بالفعل مفتوحة، فسوف تفقد أي عمل قمت به على ذلك، وسوف تضطر إلى القيام بذلك يدويا تكرارا. لذلك أنا أفكر فقط فحص لمعرفة ما إذا كان الملف مفتوح بالفعل ومن ثم إما تحرير قفل، أو مجرد جعل منبثقة قائلا: "مهلا، إذا حاولت حفظ كنت ستعمل تخيب". هل هناك طريقة سهلة لتحقق لمعرفة ما إذا كان الملف مفتوح بالفعل في جافا سكريبت؟
ورمز لفتح الملف ...
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.
لا تنتمي إلى StackOverflow