Re: Copying files via applescript
Re: Copying files via applescript
- Subject: Re: Copying files via applescript
- From: Graff <email@hidden>
- Date: Fri, 11 Jun 2004 08:45:11 -0400
On Jun 10, 2004, at 1:54 PM, Brian Dent wrote:
Thanx for the help. the script worked just fine except i realized that
it doesn't copy the files in subfolders of the folder.
[snip]
I guess basically it needs to copy over the entire contents of the
folder and its subfolders.
Ahh, you also wanted to descend into subfolders? Do you also want to
keep the folder structure intact? That's a bit more thorny of a
problem.
I believe that I have a solution. It's a whopper but it seems to work
just fine. Let me know if it doesn't come through the list server
properly and I'll send you a copy directly:
----
-- change these variables to point to whatever folders you want
set labsFolder to (path to documents folder as string) & "labs:"
set destFolder to "LEXAR_MEDIA:JavaProgs:labs:"
try
tell application "Finder"
if (folder labsFolder exists) then
if (folder destFolder exists) then
set theList to every item of folder labsFolder
repeat while (length of theList > 0)
set theItem to item 1 of theList
set theName to name of theItem
set relativePath to my StripPath(labsFolder, theItem as
string, theName)
if (class of theItem is folder) then
if not (folder (destFolder & relativePath & name of
theItem) exists) then
make new folder at folder (destFolder & relativePath)
with properties {name:theName}
end if
set theList to theList & (every file of theItem)
else
set checkFile to destFolder & relativePath & theName
if ((file checkFile) exists) then
if ((modification date of file checkFile) is less than
(modification date of theItem)) then
duplicate theItem to folder (destFolder & relativePath)
with replacing
display dialog "replacing " & checkFile
else
-- this can be removed for silent operation
display dialog "There is already a current version of
the file \"" & theName & "\" in the folder."
end if
else
duplicate theItem to folder (destFolder & relativePath)
end if
end if
set theList to rest of theList
end repeat
else
display dialog "The folder \"" & destFolder & "\" does not
exist."
end if
else
display dialog "The folder \"" & labsFolder & "\" does not exist."
end if
end tell
on error
try
tell application "Finder"
display dialog "An error occured. Unable to complete the backup"
end tell
end try
end try
-- trim_line sub-routine found at:
-- <
http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.07.htm>
--
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as
string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as
string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line
on StripPath(parentPath, theItemPath, theName)
set thePath to my trim_line(theItemPath, ":", 0)
set thePath to my trim_line(thePath, parentPath, 0)
set thePath to my trim_line(thePath, ":", 1)
set thePath to my trim_line(thePath, theName, 1)
if (length of thePath > 0) then
set thePath to my trim_line(thePath, ":", 2)
if (length of thePath > 0) then
set thePath to thePath & ":"
end if
end if
return thePath
end StripPath
----
- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.