• 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: Get filestructure in a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get filestructure in a variable


  • Subject: Re: Get filestructure in a variable
  • From: kai <email@hidden>
  • Date: Wed, 25 Oct 2006 01:07:22 +0100


On 23 Oct 2006, at 17:38, Michelle Steiner wrote:

On Oct 23, 2006, at 3:24 AM, Jan Bultereys wrote:

But I need {"00000-10000/", "10000-20000/", "50000-60000/", "80000-90000/",
"LOGO/"}


And Idealy would be to give me this output (with substructure example
NewImage)
{"00000-10000/NewImage/", "10000-20000/", "50000-60000/", "80000-90000/",
"LOGO/"}

tell application "Finder" set foo to name of (folders of disk "deety") repeat with bar in foo set contents of bar to bar & "/" end repeat end tell foo

It's still not entirely clear to me what your precise aim is here, Jan - but here are one or two more suggestions, FWIW. (The results below are based on the folder structure indicated - with one or two additions, at a slightly deeper level, to help demonstrate the later routines.)


Another way to append some text to every item from a list of text is, of course, to use text item delimiters.

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

to append_text of t to l
	if (count l) is 0 then return l
	set d to text item delimiters
	set text item delimiters to t & return
	set l to paragraphs of ((l as Unicode text) & t)
	set text item delimiters to d
	l
end append_text

append_text of "/" to list folder (choose folder) without invisibles

--> {"00000-10000/", "10000-20000/", "50000-60000/", "80000-90000/", "LOGO/"}

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

Just expanding a little on Michelle's suggestion, the following will append the name of the first sub-folder (if one exists):

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

on folder_structure from f
	tell application "Finder"
		set l to f's folders
		repeat with i in l
			tell i's first folder to if exists then
				set i's contents to i's name & "/" & name & "/"
			else
				set i's contents to i's name & "/"
			end if
		end repeat
	end tell
	l
end folder_structure

folder_structure from choose folder

--> {"00000-10000/NewImage/", "10000-20000/", "50000-60000/", "80000-90000/", "LOGO/"}

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

If a primary folder contained more than one sub-folder, you might wish to list each one:

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

on folder_structure from f
	set d to text item delimiters
	set text item delimiters to {""}
	tell application "Finder"
		set l to f's folders
		repeat with i in l
			tell i's folders to if (count) > 0 then
				set i's contents to it as Unicode text
			else
				set i's contents to i as Unicode text
			end if
		end repeat
	end tell
	repeat with i in {{f as Unicode text, return}, {":", "/"}, {return, d}}
		set l to l as Unicode text
		set text item delimiters to i's beginning
		set l to l's text items
		set text item delimiters to i's end
	end repeat
	rest of l
end folder_structure

folder_structure from choose folder

--> {"00000-10000/NewImage/", "00000-10000/NewImage 2/", "10000-20000/", "50000-60000/", "80000-90000/", "LOGO/"}

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

You may even want to dig deeper into the hierarchy - perhaps something like this:

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

to sort_items from i
	script o
		property l : i
	end script
	considering case
		repeat with i from 2 to count o's l
			set v to o's l's item i
			repeat with i from (i - 1) to 1 by -1
				tell o's l's item i to if v < it then
					set o's l's item (i + 1) to it
				else
					set o's l's item (i + 1) to v
					exit repeat
				end if
			end repeat
			if i is 1 and v < o's l's beginning then set o's l's item 1 to v
		end repeat
	end considering
end sort_items

on folder_structure from f
set d to text item delimiters
set text item delimiters to {""}
tell application "Finder"
set l to folders of f's entire contents
repeat with i in l
if (count i's folders) is 0 then set i's contents to i as Unicode text
end repeat
end tell
set l to every Unicode text of l
repeat with i in {{f, return}, {":", "/"}, {return, d}}
set l to l as Unicode text
set text item delimiters to i's beginning
set l to l's text items
set text item delimiters to i's end
end repeat
set l to rest of l
sort_items from l
l
end folder_structure


folder_structure from choose folder

--> {"00000-10000/NewImage 2/", "00000-10000/NewImage/folder 1/", "00000-10000/NewImage/folder 2/", "10000-20000/", "50000-60000/", "80000-90000/", "LOGO/"}

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

---
kai


_______________________________________________ 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/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Get filestructure in a variable (From: Jan Bultereys <email@hidden>)
 >Re: Get filestructure in a variable (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: "~" vs. "POSIX file"
  • Next by Date: Re: Importing/parsing CSV files
  • Previous by thread: Re: Get filestructure in a variable
  • Next by thread: Applescript to trap when I insert my ipod?
  • Index(es):
    • Date
    • Thread