statfs

icon-note.gif NOTE
The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import statfs from '@ohos.statfs';

Guidelines

Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see getOrCreateLocalDir of the Context module.

Absolute file or directory path = Application directory + File name or directory name

For example, if the application directory obtained by using getOrCreateLocalDir is dir and the file name is xxx.txt, the absolute path of the file is as follows:

let path = dir + "xxx.txt";

statfs.getFreeBytes

getFreeBytes(path:string):Promise<number>

Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

  • Parameters
Name Type Mandatory Description
path string Yes File path of the file system.
  • Return value
Type Description
Promise<number> Promise used to return the number of free bytes obtained.
  • Example

    let path = "/dev";
    statfs.getFreeBytes(path).then(function (number){
        console.info("getFreeBytes promise successfully:"+ number);
    }).catch(function(err){
        console.info("getFreeBytes failed with error:"+ err);
    });
    

statfs.getFreeBytes

getFreeBytes(path:string, callback:AsyncCallback<number>): void

Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a callback to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

  • Parameters
Name Type Mandatory Description
path string Yes File path of the file system.
callback AsyncCallback<number> Yes Callback invoked to return the number of free bytes obtained.
  • Example

    statfs.getFreeBytes(path, function(err, number){
        console.info("getFreeBytes callback successfully:"+ number);
    });
    

statfs.getTotalBytes

getTotalBytes(path: string): Promise<number>

Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a promise to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

  • Parameters
Name Type Mandatory Description
path string Yes File path of the file system.
  • Return value
Type Description
Promise<number> Promise used to return the total number of bytes obtained.
  • Example

    let path = "/dev";
    statfs.getTotalBytes(path).then(function (number){
        console.info("getTotalBytes promise successfully:"+ number);
    }).catch(function(err){
        console.info("getTotalBytes failed with error:"+ err);
    });
    

statfs.getTotalBytes

getTotalBytes(path: string, callback: AsyncCallback<number>): void

Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a callback to return the result.

System capability: SystemCapability.FileManagement.File.FileIO

  • Parameters
Name Type Mandatory Description
path string Yes File path of the file system.
callback AsyncCallback<number> Yes Callback invoked to return the total number of bytes obtained.
  • Example

    statfs.getTotalBytes(path, function(err, number){
        console.info("getTotalBytes callback successfully:"+ number);
    });