• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Duplicating files from path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Duplicating files from path


  • Subject: Re: Duplicating files from path
  • From: Jolly Roger <email@hidden>
  • Date: Tue, 20 Feb 2001 12:06:32 -0600
  • Replyto: email@hidden

on 2/20/2001 10:57 AM, Phil Burk (email@hidden) wrote:

> I know this is incredibly obvious but I have not been able to figure out how
> to duplicate the file in the variable as its *complete* path on the local
> workstation. Here's my script:

You will have to create the folder hierarchy yourself. I would suggest that
you do something similar to the following for each file:

-- Encoded with AppleScript Endec 1.0.3
set sourceFile to choose file with prompt "Choose a file to copy:"
set destFolder to choose folder with prompt "Choose the destination folder:"

my DuplicateHeirarchy(sourceFile, destFolder)

on DuplicateHeirarchy(sourceFile, destFolder)

-- first get the heirarchy
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set hierarchy to the text items of ParentFromPath(sourceFile, true)
set AppleScript's text item delimiters to saveDelims
set hierarchy to (items 1 thru -2 of hierarchy) -- remove last empty item

-- step through all levels and duplicate the hierarchy
repeat with h from 1 to the count of hierarchy
set nextFolderName to (item h of hierarchy) as text
if not my FileExists((destFolder & nextFolderName & ":") as text) then
try
tell application "Finder" to make new folder at (alias destFolder)
with properties {name:nextFolderName}
on error errmsg number errnum
-- error -48 = folder with that name exists - ignore
if errnum `AD -48 then
log errmsg
log errnum
end if
end try
end if
set destFolder to (destFolder & nextFolderName & ":") as text
end repeat

-- copy the file now
tell application "Finder" to duplicate (alias sourceFile) to (alias
destFolder) with replacing

end DuplicateHeirarchy

-------------------------------------------------------------------------

on FileExists(theFilePath)
try
set theAlias to (theFilePath as alias)
return true
on error
return false
end try
end FileExists

-------------------------------------------------------------------------

on ParentFromPath(thePath, wantPath)
set thePath to (thePath as text)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 2
else
set idx to -2
end if
if wantPath then
set folderName to ((text items 1 through idx of pathAsList) as text) &
":"
else
set folderName to item idx of pathAsList
end if
set AppleScript's text item delimiters to saveDelim
return folderName
end ParentFromPath

HTH

JR


References: 
 >Duplicating files from path (From: Phil Burk <email@hidden>)

  • Prev by Date: screenshot
  • Next by Date: Re: Styles in AppleWorks??
  • Previous by thread: Duplicating files from path
  • Next by thread: Re: Duplicating files from path
  • Index(es):
    • Date
    • Thread