# How to overwrite a file?

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-overwrite-a-file/3875>\
**Category:** UXP Plugin API\
**Created:** [November 10, 2021, 1:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-overwrite-a-file/3875 "2021-11-10T13:03:39Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Rip](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@Rip](https://forums.creativeclouddeveloper.com/u/Rip)\
**Post date:** [May 20, 2024, 7:18pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-overwrite-a-file/3875/11 "2024-05-20T19:18:07Z")

</div>

Thanks.

1. I was able to get fs to delete the file created by a previous run of my plugin like this:

> let path = app.activeDocument.path  
> let lastIndexOf = path.lastIndexOf(“\”)  
> path = path.slice(0, lastIndexOf+1);  
> path = path.replaceAll(“\”, “/”)  
> fileName = “test\_file\_to\_delete.tif”  
> const directFS = require(‘fs’)  
> fileDeleted = await directFS.unlink(“file:”+path+fileName);

1. Also, I discovered that if I moved the delete operation for other files ahead of the save operation for the new file, LFS deleted all of the files without throwing the error “FileSystemProvider: You don’t have permission on this file”.

I’m unclear as to the reason the sequence of deleting unrelated files is important.

I’d still like to use fs to save a log file to the same directory as the new TIF.

Based on the examples here:

> [@UXP accessing files and folders](http://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/17):
>
> Oh sorry I had forgotten. . on your manifest 5 add this after icons. "requiredPermissions": { "localFileSystem": "fullAccess", // this is important for the access // with regards to the question the rest is not of much importance "network": { "domains": ["http://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/15",] }, "launchProcess": { "schemes": [ …

Fs requires double backlashes instead of single forward slashes on a Mac, like this:  
file:c:\path\to\allowed\file.json

Which of these functions will return a string with double slashes on a Mac?  
anEntry.nativePath  
homedir()  
document.path

And will they be the required back slashes, or will the slashes have to be reversed, like on a PC?

Thanks again!

---

_[View the full topic](https://forums.creativeclouddeveloper.com/t/how-to-overwrite-a-file/3875)._
