0

I have tried fs unlink/unlinksys remove/removesys. But nothing works.

Once my app quits these files are not being deleted.

Any ideas how I can wipe the whole folder, even if some files are being used when funcs are being triggered on Windows OS?

Any library's or raw js?

I have a angularjs app that is super small and everything but once i log off from app i want to delete everything in "path"

So im using:

fs.removeSync(path);

Which works like a charm on linux, but on windows it does not. Cause same files are still being used by app(obv cause app is in middle of running that function)

Unfortunately not sure what code should i post. Cause thats all there is and it works on linux. On win it does not. How can i make it work on win? Flag it somehow to delete or idk?

  • Can you please add a bit more details on what you want to achieve and want you tried so far? Better if you add the code snippet that you are using – Abrar Jun 07 '18 at 11:58
  • Updated! Nothing much to say about code. I use fs.removesync(path) which works on linux but not on windows – Darknjan994 Jun 07 '18 at 12:10

1 Answers1

0

It is not possible to delete open files on Windows due to architecture choices. Ie. it simply works differently than for Linux & Mac, and you need to resolve to clunky workarounds.

For your use-case, you need to ensure that all files are closed before doing the delete. If you are lucky, and no other process has opened one of your files, it should work. Otherwise, you can try a few times...

For a bit of context, you can check out https://github.com/isaacs/rimraf/issues/72 & Will we ever be able to delete an open file in Windows?.

Gil
  • 3,529
  • 1
  • 19
  • 22
  • Thanks Gil. I was wondering if i could do fs.writeFileSync(file.txt, 'deleted') or something alike to just mess the content of the files. What do you think? – Darknjan994 Jun 07 '18 at 15:01