简体   繁体   中英

How to get Directory size, HTML5 file api, using webkitdirectory

I am trying to use HTML5 file api + webkitdirectory in input element.

<input type="file" name="files[]" id="myfile" multiple="" directory="" webkitdirectory="" mozdirectory="">

How can I get the SIZE ()in kb/mb etc) of selected folder/directory, using javascript/jquery.

Please help as I am unable to figure it out by myself.

You can loop through the files property of the input after directory or files are selected

 $('#myfile').change(function(e) { var totalSize = [].reduce.call(this.files, function(tot, currFile) { console.log(currFile.name , ' size=', currFile.size); return tot + currFile.size; }, 0); console.log('Total size = ', totalSize) }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="file" name="files[]" id="myfile" multiple="" directory="" webkitdirectory="" mozdirectory=""> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM