2016-02-11 65 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浏览器。 –

相关问题