deleteFile
Description
Deletes a file if it exists. If deletion succeed, it will resolve the fileLocationAndName parameter. If it fails, it will reject either a StringValidationError, ENOENT or a DeletingFileError.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function deleteFile(fileLocationAndName[, tuple]): Promise<string || Array> |
Examples
1
2
3
4
import {deleteFile} from 'puddy-m/lib/fileFunctions'
deleteFile('path/to/file.ext')
.then(filePath=>console.log(filePath)) // prints 'path/to/file.ext'
1
2
3
4
import {deleteFile} from 'puddy-m/lib/fileFunctions'
deleteFile(true)
.catch(e=>e) // rejects an instance of StringValidationError.
1
2
3
4
5
6
// Using it with tuple parameter
import {deleteFile} from 'puddy-m/lib/fileFunctions'
deleteFile('path/to/file.ext', [])
.then(tuple=>validateString("World", tuple))
.then(([first, second])=> first + second) // 'path/to/file.extWorld'