# Prevent Files from being overwritten

**URL:** <https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128>\
**Category:** Third Party Plugins\
**Created:** [August 16, 2018, 3:19pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128 "2018-08-16T15:19:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/thomas/32/61_2.png) [@Thomas](https://forum.pinegrow.com/u/Thomas)\
**Post date:** [August 16, 2018, 3:19pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128/1 "2018-08-16T15:19:29Z")

</div>

Hi guys,

am working a bit further on my Reginald-Framework Plugin. The previous version pointed to remote URLs for loading the required resources (CSS and JS).

Now I thought, it might be better to create local resources. I grabbed the following script (thanks to @benhanna 🙂)

```
        //Add resources as component (locally)
    
    var toLocalPath = function(p) {
    return p.replace(/\//g, path.sep);
    }
    
    var res_files = ['themagicstyles-min.css', 'overwriterules.css', 'themagicscript-min.js'];
    for(var i = 0; i < res_files.length; i++) {
    var file = f.getResourceFile('resources/' + res_files[i]);
    var r = new PgComponentTypeResource(file);
    r.relative_url = res_files[i];
    r.source = toLocalPath(file);
    r.footer = res_files[i].indexOf('.js') >= 0;
    f.resources.add(r);
    }

```

It does what it is opposed to.

But when I create a new page and load the plugin, the files will be overwritten - as expected as well (I suppose it’s the p.replace.

Is there a way to prevent me from “replace”?

Or is my idea stupid anyway?

Thanks for your help in advance.

Cheers

Thomas

---

<div class="post-metadata">

**Author:** ![SureWeb](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@SureWeb](https://forum.pinegrow.com/u/SureWeb)\
**Post date:** [August 16, 2018, 10:11pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128/2 "2018-08-16T22:11:10Z")

</div>

Hi Thomas,

p.replace() is using a regular expression to replace the file path separator pc-web. I have thought about creating a plugin but haven’t created one yet. I think if I were doing it I would edit those files in an external editor and then reload the plugin to see the effects. Or work on it as a seperate project and then dump the files into the plugin.  
It would be interesting to see what Ben’s approach is.  
🙂

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/thomas/32/61_2.png) [@Thomas](https://forum.pinegrow.com/u/Thomas)\
**Post date:** [August 17, 2018, 5:23pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128/3 "2018-08-17T17:23:30Z")

</div>

OK - got it!  
Cannot explain what I did though.  
In fact I had a look into Ben’s great work (the pervious code I had is admittedly not from him - apologize) trying to figure out what’s going on. And with a bit of trying, it started to work. So always remember (Note to myself):  
“99% of the mistakes are sitting in front of the screen”.

Cheers

Thomas

---

<div class="post-metadata">

**Author:** ![benhanna](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/benhanna/32/766_2.png) [@benhanna](https://forum.pinegrow.com/u/benhanna)\
**Post date:** [August 21, 2018, 2:46pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128/4 "2018-08-21T14:46:29Z")

</div>

@SureWeb  
I use an external editor, a lot of trial and error and looking at the frameworks bundled with PG for tips as not much info in the docs. Constant loading and unloading of Plugin to test. I find you need to completly unload the plugin JS file in PG and the reload and activate it each time when testing, to see updates (not just deactivate and reactivate).

---

<div class="post-metadata">

**Author:** ![benhanna](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/benhanna/32/766_2.png) [@benhanna](https://forum.pinegrow.com/u/benhanna)\
**Post date:** [August 21, 2018, 3:00pm UTC](https://forum.pinegrow.com/t/prevent-files-from-being-overwritten/2128/5 "2018-08-21T15:00:33Z")

</div>

@Thomas

I know you got sorted but maybe this was what you were looking for (from the FA plugin)

```
 //Auto detect if font-awesome css is included
    f.detect = function(pgPage) {
        return pgPage.hasStylesheet(/font\-awesome/i);
    }
```
