I need to copy a selection of files and folders preserving their attributes and structure.
I want to use ‘cp’ but, can’t get it to copy the folders themselves. This is a test:
tell application "Finder"
set sourceItemPath to (path to documents folder as text) & "zzzz:" -- 'zzzz:' is just a test folder with some contents.
set targetFolderPath to path to desktop
end tell
tell current application
do shell script "cp -pR " & quoted form of POSIX path of sourceItemPath & " " & quoted form of POSIX path of targetFolderPath
--> copies ONLY the contents of 'zzzz:' but, NOT the folder itself.
end tell
It does actually do what the the man says: if the source ends with ‘/’ then it copies only the contents. But, how do I tell ‘cp’ to copy the folder itself?
I know that in AS I can strip the end ‘/’ by testing the item for kind and, if it is a folder, use a construct like this:
tell application "Finder"
set sourceItemPath to alias ((path to documents folder as text) & "zzzz:")
set sourceItemPath to (container of sourceItemPath as text) & name of sourceItemPath
set targetFolderPath to path to desktop
end tell
tell current application
do shell script "cp -pR " & quoted form of POSIX path of sourceItemPath & " " & quoted form of POSIX path of targetFolderPath
--> copies the folder itself, complete with all contents, preserving all atributes and folder structure.
end tell
but, isn’t there a ‘cp’ syntax to copy a folder complete with folder structure and attributes?