• 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: Copying folder structures
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying folder structures


  • Subject: Re: Copying folder structures
  • From: Ed Stockly <email@hidden>
  • Date: Tue, 25 Dec 2007 14:02:14 -0800

Originally i was looking for a plain AS solution because i'm not
familiar with the shell script thingies at all.



Here's another appleScript solution that's a bit more flexible and maybe a little faster than the other appleScript solutions posted. More flexible in that it tests to see if a folder is already in place before running, which allows you to run the script multiple times and get any new folders.

It may be faster in that it doesn't rely on the Finder as much for manipulating the folder names and paths. (It may not be faster because it does test to see if each folder already exists. It could be sped up by eliminating the check for an existing folder.

HTH,

ES

set folderToClone to path to documents folder
set cloneDestination to alias "Macintosh HD:Users:edstockly:Desktop:untitled folder:"
set AppleScript's text item delimiters to ""
set cloneDestination to text items 1 thru -2 of (cloneDestination as string) as string
tell application "Finder"
  set folderContents to every folder of entire contents of folderToClone
end tell
set finishedPaths to {}
repeat with thisFolder in folderContents
  set AppleScript's text item delimiters to folderToClone as string
  set myFolder to thisFolder as string
  set endFolderPath to (the rest of every text item of myFolder) as string
  set AppleScript's text item delimiters to ":"
  set endFolderPath to text items 1 thru -2 of endFolderPath
  set folderToDupe to {cloneDestination as string}
  repeat with x from 1 to (the (count of endFolderPath))
    set the end of folderToDupe to item x of endFolderPath
    set testFolderPath to folderToDupe as string
    if testFolderPath is not in finishedPaths then
      try
        set thisPathAlias to testFolderPath as alias
      on error
        set newFolderName to text item -1 of testFolderPath
        set newFolderPath to (text items 1 thru -2 of testFolderPath) as string
        tell application "Finder"
          make new folder at folder newFolderPath with properties {name:newFolderName}
        end tell
      end try
    end if
  end repeat
end repeat
=
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Organizing AppleScripts
  • Next by Date: Rich text to ... something else. And vice versa
  • Previous by thread: Re: Copying folder structures
  • Next by thread: Searching events in iCal
  • Index(es):
    • Date
    • Thread