Languages

Menu
Sites
Language
How to get file size in File System

Hi,

  I am developing File Manager, I need to show file size. Could any one help me in getting FILE SIZE.

 

Thanks in Advance

Responses

6 Replies
daniel kim

Hi,

I would suggest you to refer to below code and privilege <tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>  is required to run this code.

function onsuccess(files) {  
     for (var i = 0; i < files.length; i++) {
 
       console.log("name " + files[i].name);
       console.log("filesize " + files[i].fileSize);
  
     }
   }

   function onerror(error) {
     console.log("The error " + error.message +
                 " occurred when listing the files in the selected folder");
   }


   tizen.filesystem.resolve(
       'documents',
       function(dir) {
         documentsDir = dir;
         dir.listFiles(onsuccess, onerror);
       }, function(e) {
         console.log("Error" + e.message);
       }, "rw"
  );
    

 

function onsuccess(files) {  
     for (var i = 0; i < files.length; i++) {
 
       console.log("name " + files[i].name);
       console.log("filesize " + files[i].fileSize);
  
     }
   }

   function onerror(error) {
     console.log("The error " + error.message +
                 " occurred when listing the files in the selected folder");
   }


   tizen.filesystem.resolve(
       'documents',
       function(dir) {
         documentsDir = dir;
         dir.listFiles(onsuccess, onerror);
       }, function(e) {
         console.log("Error" + e.message);
       }, "rw"
  );
    

 

Regards

daniel kim

f.y.i ) code was duplicated here :(

Palitsyna

Hello,

you can use the following code to get file size:

var directory = "images",
file = null;

tizen.filesystem.resolve(directory, function(dir){ 
		dir.listFiles(onsuccess, onerror);

		function onsuccess(files) {
			for (var i = 0; i < files.length; i++) {
				console.log("name: " + files[i].name + " size = " + files[i].fileSize + " bytes");
			}
		}

		function onerror(error) {
			console.log("The error " + error.message + " occurred when listing the files in the selected folder");
		}

		alert(file.fileSize);
	}, function(e) {console.log("Error" + e.message);}, "rw");

 

Here is FileSystem API: https://developer.tizen.org/dev-guide/2.3.1/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html

Vikram

Hi,

You can get the filesize through File interface. The File interface represents the file abstraction in use.

And the method is 

readonly attribute unsigned long long fileSize

AVSukhov

Hello,

All info you can find in documentation: please refer to Filesystem API -> File interface. File interface has all necessary attributes (in your case fileSize).

Vikram

Hi,

You also can get the specic one file size in filesystem, refer to below code,

function getfilesize(){
    var file;
	var directory = '/opt/usr/media/Documents/';
	tizen.filesystem.resolve(
			directory, 
			function(dir){
		        file = dir.resolve("x.txt");
		        alert(file.fileSize);
	        },  
	        function(e){console.log("error" + e.message)}, "rw");	
}