Bash for loop Script or Service to Copy Folders and Archive in one go?

May you try with the ASObjC script ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 18:07:19

I’d be happy to do that but you would have to supply the working code. The source folder would be as shown above. The destination folder would be:

“Save:Test:asobjc:”

You may test that:

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

on copyItemAt:POSIXPath toFolder:POSIXDest
	set sourceURL to current application's class "NSURL"'s fileURLWithPath:POSIXPath
	set theName to sourceURL's lastPathComponent()
	set destURL to current application's class "NSURL"'s fileURLWithPath:POSIXDest
	set destURL to destURL's URLByAppendingPathComponent:theName
	set fileManager to current application's NSFileManager's defaultManager()
	if (destURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean then
		-- the folder already exists, delete it
		fileManager's removeItemAtURL:destURL |error|:(missing value)
	end if
	if theName as string is "Records" then
		set {theResult, theError} to fileManager's copyItemAtURL:sourceURL toURL:destURL |error|:(reference)
	else
		set {theResult, theError} to fileManager's moveItemAtURL:sourceURL toURL:destURL |error|:(reference)
	end if
	if (theResult as boolean) is false then
		error (theError's localizedDescription() as text)
	end if
end copyItemAt:toFolder:


-- If you try with a sourceFolder named "Records" it will be copied
-- If it's not named "Records" it will be moved
my copyItemAt:"/Users/Robert/Records" toFolder:"/Volumes/Save/Test/asobjc/"

(*
-- I tested with :
set sourceContainer to path to desktop as string
set destContainer to my remplace(sourceContainer, "SSD 1000", "Macintosh HD")
set folderToCopy to sourceContainer & "Print:" -- or "ableton:"
my copyItemAt:(POSIX path of folderToCopy) toFolder:(POSIX path of destContainer)
*)

#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
	set l to text items of t
	set AppleScript's text item delimiters to d2
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end remplace

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 19:08:16

Thank you.

As shell is not my cup of tea, I’m not really concerned by what is available and what isn’t in this area.

At this time I just wish to know which behavior is the one really wanted by the OP.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 23:29:39

That’s not the case with APFS volumes. Copying works very much like moving, with seperate contents only made when one or the other is modified (and even then, only of the modified part).

Yvan,

You could make your script more efficient by ignoring files that have not changed, something like this:

if not (fileManager's contentsEqualAtPath:POSIXPath andPath:(destURL's |path|())) then

But that’s only going to work with files, not folders or packages.

Thank you Shane but I tried to achieve what was described by the OP:

If I read well, it was asked to copy the folders with their subfolders, not to copy only newly added or changed items.
It’s the way I work for my files because I like to keep old versions which may prove to be useful one day. I retrieve them in the date stamped archives.
It resemble to what is done by Time Machine which keep the old versions (as well as the hidden folder .DocumentRevisions-V100 from which I extracted numerous Pages or Numbers documents to help really annoyed askers).
If I understand well the schemes proposed by Peavine replace the old versions by the new ones.
I don’t criticize this behavior, it’s just not what was asked (at least the way I understood the question which may be the wrong one).

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 10 mai 2020 10:44:06

Hi Shane, in my message I carefully wrote:

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 10 mai 2020 16:19:02

Thanks everyone,

Like someone said here in this post, there’s enough here to cobble up a good script.
I apologize for my poor description of my results.
I never expected such audacious effort to help me with my request. I really appreciate everyone’s contributions. I will take a few hours to suit a script for my unique special needs. Thanks again. ???

Yvan,

I missed that, sorry. But the key point is that it’s not the version of macOS, but rather the format of the disk.

Thank’s Shane.
I read too fast the infos about changes and didn’t took care that these ones are linked to the format nt to the version of OS.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 11 mai 2020 08:49:32