2016-02-11 67 views
1

我使用下面的代碼來選擇一個目錄,並從該目錄的Javascript檢查文件是否可讀可寫或可執行

<input type="file"onchange="checkFiles(this.files)" webkitdirectory directory multiple> 

在下面的代碼我能夠在目錄中讀取每個文件,它讀取每個文件屬性如名稱,大小和類型。 但沒有找到任何方法來檢查文件是否可讀,可寫或可執行。

function checkFiles(files) { 
    for (var i = 0; i < files.length; i++) { 
     //check for readable writable or executable files 
    } 
} 
+1

沒有。這裏是File對象:https://developer.mozilla.org/en-US/docs/Web/API/File –

+1

可讀/可寫/可執行文件是文件系統和操作系統權限,而不是文件本身的屬性。 –

回答

0

如果可寫=不是隻讀,那麼也許你可以嘗試使用this的例子。如Dan-o提到的,這隻適用於Internet Explorer。

對於其他瀏覽器兼容性,請嘗試深入瞭解 activex object in firefox or chrome not ie

function get() { 
    var myObject, f; 
    myObject = new ActiveXObject("Scripting.FileSystemObject"); 
    f = myObject.GetFile("c:\\test.txt"); 

    if(!f.attributes) { 
     //No attributes set 
    } 
    else { 

     if (f.attributes & 1) { 
      //Read only 
     } 

     else if (f.attributes & 2) { 
      //Hidden 
     } 

     else if (f.attributes & 4) 
      //System 
     } 

     else if (f.attributes & 8) { 
      //Volume label 
     } 

     else if (f.attributes & 16) { 
      //Folder 
     } 

     else if (f.attributes & 32) { 
      //Archive bit set 
     } 

     if (f.attributes & 64) { 
      //Shortcut or link 
     } 

     if (f.attributes & 128) { 
      //File is compressed 
     } 
    } 

您可以將此與gettnig文件的MIME類型結合使用。

+1

你應該提到它只是IE瀏覽器。 –

相關問題