Is there a javascript or zotero function to move a file to trash instead of delete it directly from disk?

62 views
Skip to first unread message

Minyi Han

unread,
Sep 3, 2021, 8:50:59 AM9/3/21
to zotero-dev
zacurry suggested 3rd party solutions, however I have no idea how to use npm in zotero run javascript window.

Origin post:
Now the function OS.File.remove (file) was used, where file is the path, for example d:/files/aa.txt, however the file was removed directly from disk. Is there a function to move the file to the trash (Windows or Linux)?

Dan Stillman

unread,
Sep 3, 2021, 6:43:58 PM9/3/21
to zoter...@googlegroups.com
Note that this doesn't have anything to do with "JavaScript" — OS.File.remove() is specific to the Mozilla internals (and outdated ones, at that) used in Zotero. This isn't really a question for Stack Overflow.

There's no API for that in Mozilla or Zotero, and it's not something you can really do in a proper way on other people's systems (where you'd be limited to mv [1]).

[1] https://github.com/sindresorhus/trash#but-i-can-do-the-same-thing-with-mv

Minyi Han

unread,
Sep 18, 2021, 2:15:39 AM9/18/21
to zotero-dev
Thanks Dan for your kindly reply.

Minyi Han

unread,
Nov 7, 2021, 1:53:30 AM11/7/21
to zotero-dev
Could the npm command be applied in JS code?

npm install trash

Then we could use trash command.

Minyi Han

unread,
Jan 24, 2022, 7:47:22 PM (3 days ago) Jan 24
to zotero-dev
Could these JS ( trash/lib at main · sindresorhus/trash (github.com)  )be integrated into the plugin I made, then the trash command be used?

Emiliano Heyns

unread,
Jan 26, 2022, 4:12:06 PM (yesterday) Jan 26
to zotero-dev
The user would have to have node installed. Alternately, you could bundle the executables from the trash npm module, and call them with Zotero.Utilities.Internal.exec

Minyi Han

unread,
Jan 26, 2022, 7:32:23 PM (yesterday) Jan 26
to zotero-dev
Thanks Emiliano Heyns. Need I install nmp application first? And how to bundle  executables? Is there an example or code snippet?
Reply all
Reply to author
Forward
0 new messages