Backup and Make Read Only

Hi Guys,

I use this simple code to backup files into a 'backup' folder:

Copy HERE CREATEFOLDER="Backup"

I want to make the files read only but I am not sure how to do it. I can select all files in the backup folder and make them all read only but this is not efficient if there are loads fo files already in there.

Any help will be much appreciated.

Regards

Blueroly

Copy HERE CREATEFOLDER="Backup"
SetAttr {sourcepath}Backup\* SETATTR=r RECURSE

Might get inefficient if the backup folder contains a lot of old files, since it'll be adding the R attribute to everything (old and new) in the folder. If that becomes a problem, a more complex script would be needed to only change the things that are copied.

1 Like

Works perfectly, thanks Leo :+1:

1 Like

I did consider this but it's unlikely that I will actually need to backup more than a few files before eventually deleting them so this works perfectly.

Wouldn't a simple temp folder do the trick?

Copy HERE CREATEFOLDER=temp
SetAttr {sourcepath}temp\* SETATTR=r RECURSE
CreateFolder NAME=Backup
Copy MOVE FILE={sourcepath}temp\* TO={sourcepath}Backup
Delete FILE=temp QUIET

Seems OK, as long as you know you won't ever have an existing "temp" folder in the same place you'll use it.

That works perfectly, thanks lxp.

Good thinking... there's a good chance an existing temp folder will exist in certain folders but if I call it tempxyz, problem solved.

Thank you both for your help on this one, there may be one more question tomorrow but as ever I'll try and work it out myself first :grinning:

I give up!

I need a similar button but this one should prefix the backed up files with the date & time.

i.e. FROM: File To Be Backed Up.dop TO [20190501 12-17-52] File To Be Backed Up.dop

Copy HERE CREATEFOLDER=TempSJW
Rename PATTERN="{sourcepath}TempSJW\*.*" TO="[{date|yyyyMMdd} {time|HH-mm-ss}] *.*" AUTORENAME TYPE=files
SetAttr {sourcepath}TempSJW\* SETATTR=r RECURSE
CreateFolder NAME=Backup
Copy MOVE FILE={sourcepath}TempSJW\* TO={sourcepath}Backup
Delete FILE=TempSJW QUIET

The problem is with the line which seemingly does nothing:

Rename PATTERN="{sourcepath}\TempSJW\*.*" TO="[{date|yyyyMMdd} {time|HH-mm-ss}] *.*"

Where am I going wrong this time?

Copy HERE CREATEFOLDER=TempSJW
Rename {sourcepath}TempSJW\* PATTERN="*" TO="[{date|yyyyMMdd} {time|HH-mm-ss}] *" AUTORENAME TYPE=files
SetAttr {sourcepath}TempSJW\* SETATTR=r RECURSE
CreateFolder NAME=Backup
Copy MOVE FILE={sourcepath}TempSJW\* TO={sourcepath}Backup
Delete {sourcepath}TempSJW QUIET

(I changed the last line as well, mostly for consistency. Maybe all the {sourcepath} could be removed as well; haven't tried that.)

This is weird, it works as expected when I run the command on a single file but when I select multiple files, each file gets prefixed with the date & time multiple times.

Single file:
[20190501 14-15-42] File To Be Backed Up A.dop :heavy_check_mark:

Two Files:
[20190501 14-21-34] [20190501 14-21-34] File To Be Backed Up F.dop :x:
[20190501 14-21-34] [20190501 14-21-34] File To Be Backed Up G.dop :x:

Three Files:
[20190501 14-16-38] [20190501 14-16-38] [20190501 14-16-38] File To Be Backed Up C.dop :x:
[20190501 14-16-38] [20190501 14-16-38] [20190501 14-16-38] File To Be Backed Up D.dop :x:
[20190501 14-16-38] [20190501 14-16-38] [20190501 14-16-38] File To Be Backed Up E.dop :x:
etc.

I agree with that, I like consistency even if the end result is the same.

I have tried that but the rename doesn't work.

It shouldn't be needed but adding @runonce: before the rename seems to fix that:

Copy HERE CREATEFOLDER=TempSJW
@runonce:Rename {sourcepath}TempSJW\* PATTERN="*" TO="[{date|yyyyMMdd} {time|HH-mm-ss}] *" AUTORENAME TYPE=files
SetAttr {sourcepath}TempSJW\* SETATTR=r RECURSE
CreateFolder NAME=Backup
Copy MOVE FILE={sourcepath}TempSJW\* TO={sourcepath}Backup
Delete {sourcepath}TempSJW QUIET
1 Like

That works Leo, thank you very much :ok_hand: