Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Fs-Extra delete only files in a directory?

Can I do delete all files in apples directory without deleting the directory itself? fs-extra API does not describe if it is possible.

 fsExtra.remove 'apples/*', ->
    if !err
    # Do stuff
like image 805
stevek-pro Avatar asked Feb 11 '16 12:02

stevek-pro


People also ask

What is FS-extra used for?

fs-extra adds file system methods that aren't included in the native fs module and adds promise support to the fs methods. It also uses graceful-fs to prevent EMFILE errors. It should be a drop in replacement for fs .

Which method is used to delete all files in a directory?

You can use the FileUtils. cleanDirectory() method to recursively delete all files and subdirectories within a directory, without deleting the directory itself. To delete a directory recursively and everything in it, you can use the FileUtils.

How do you delete a file in fs?

In Node. js, you can use the fs. unlink() method provided by the built-in fs module to delete a file from the local file system.

How do I delete everything in a folder?

You can delete multiple files or folders by holding down the Ctrl key and clicking each file or folder before pressing Delete . You can hold down the Shift key while pressing the Delete key to prevent files from going to the Recycle Bin when deleted.


1 Answers

You can use emptyDir

Ensures that a directory is empty. If the directory does not exist, it is created. The directory itself is not deleted.

fsExtra.emptyDir 'apples/', ->
    if !err
    # Do stuff
like image 74
SlashmanX Avatar answered Oct 11 '22 16:10

SlashmanX