Skip to content

SecureErase (secure file deletion) ​

ts
function SecureErase(what: string, passes: number): boolean;

This function tries to delete the what file from the local file-system using a secure erasure algorithm. This means that the file will be overwritten with crypto-secure pseudo-random data before it’s actually deleted from the storage medium, in order to make it unrecoverable. For this reason, depending on the size of the file, this function may take a while to complete.

The second parameter passes is optional, and specifies how many times the file needs to be overwritten with crypto-secure pseudo-random data before the actual deletion occurs. If left unspecified, the file will be overwritten only once and then deleted.

This function accepts the following parameters:

ParameterTypeRequirementExplanation
whatstringrequiredmust be a valid and existing file in a local file system
passesnumberoptionalthe number of times the file should be overwritten with random data before its actual deletion, if this parameter is not specified the file will be overwritten once

Possible return values:

ValueExplanation
truethe function succeeded: the file was deleted
truethe function failed: the file was not deleted

Example (Windows file system, no optional parameter) ​

ts
{
  if (SecureErase('C:\\Data\\SomeFile.docx')) {
    // ...
  }
}

Example (Linux file system, with optional parameter) ​

ts
{
  if (SecureErase('/home/someuser/data/SomeFile.pdf', 3)) {
    // ...
  }
}