sindresorhus/trash

Add ability to disable glob matching

mofux opened this issue · 4 comments

mofux commented

I already know the files or folders I want to delete, so I simply pass them to trash in an array. Fine. Now consider this:

touch "test*.txt"
touch test1.txt
touch test2.txt
touch test3.txt

And guess what happens if I tell trash to remove the regular file "test*.txt", not good 😅

trash(['test*.txt'])

Therefore I would opt for an option that disables the globber and simply uses the file list I pass.
I'd like to create a PR if you're willing to accept. I propose an interface like this:

trash(['test*.txt'], { glob: false })
kevva commented

You can escape the character like this trash(['test\\*.txt']), which imo is a better choice than adding a new option. This is also how bash for example works.

mofux commented

@kevva If it was only for the* I would agree, but there are so many special characters in a glob pattern *, (, ), ?, !, +, @ that it would just feel strange and leave me with a somewhat bad feeling if I did escape them. In the end, this lib is about deleting files - which is the one most sensitive system action that you don't want to mess up 😅.

@kevva I could think of a different use-case. When you've already globbed or gotten the list of files using another mechanism and then pass it to trash, it could be helpful to disable globbing for performance reasons.