RE: merge same (beginning) filenames into different variables
RE: merge same (beginning) filenames into different variables
- Subject: RE: merge same (beginning) filenames into different variables
- From: "Jan-Bultereys" <email@hidden>
- Date: Thu, 19 May 2005 13:44:53 +0200
- Thread-topic: merge same (beginning) filenames into different variables
Thanks has for you reply already....
The purpose is to generated different variables just with a list of filenames....
The names of the files really does not matter BUT if they have the same beginning
they have to be declared to a variable...
example:
test10page100
test10page200
should be going in the Variable: VAR1..... etc....
testApage200
should be going in the Variable VAR2 .... etc
testBApage150
testBApage266
should be going in the Variable VAR3 ... etc
My first solution was to make a selection based on the first characters but there are too much
possibilities to use this..... so what I want is ...look for the names of the files in a folder and generated the list
of the files in different variables.....
I know it's pretty hard to explain.... but any ideas are appreciated
best regards,jan
> ----------
> From: applescript-users-bounces+jan.bultereys=email@hidden on behalf of has
> Sent: Thursday, May 19, 2005 13:03 PM
> To: email@hidden
> Subject: Re: merge same (beginning) filenames into different variables
>
> Jan-Bultereys wrote:
>
> >What I want to do is merge the files with the same "beginning" (the files are longer than the example) into different variables.
>
> You don't provide enough information for a precise solution. (e.g. What are we looking at: filenames; file contents? If the keys 'test88', 'testKK2', 'test....' are part of a larger block of data, how are they to be extracted? How are you going to use the results?) Still, the following may point you in the general direction:
>
> ======================================================================
>
> (* auto-generated library loading code *)
>
> property _Loader : run application "LoaderServer"
>
> ----------------------------------------------------------------------
> -- DEPENDENCIES
>
> property _Types : missing value
>
> on __load__(loader)
> set _Types to loader's loadlib("Types")
> end __load__
>
> ----------------------------------------------------------------------
>
> __load__(_Loader's makeLoader())
>
> (* main code *)
>
> on extractKey(theValue)
> return theValue's word 1 -- extract a value's key [YOUR CODE HERE]
> end extractKey
>
> on buildDict(lst)
> set dict to _Types's makeDict()
> repeat with itemRef in lst
> set theValue to itemRef's contents
> set theKey to extractKey(theValue)
> if dict's itemExists(theKey) then
> set end of dict's getItem(theKey) to theValue
> else
> dict's SetItem(theKey, {theValue})
> end if
> end repeat
> return dict
> end buildDict
>
> (* test *)
>
> set lst to {"88 apple", "KK2 orange", "88 pear", "KK2 tree", "A87 mouse", "BC cheese", "A87 lemon", "BC bling", "A89 navy", "B90 blue"}
>
> -- build a dictionary object containing values grouped by key
> set dict to buildDict(lst)
>
> -- retrieve all values with a common key
> --log dict's getKeys() --> list of all keys
> --log dict's getValues() --> list of all values grouped according to key
> log dict's getItem("A87") --> {"A87 mouse", "A87 lemon"}
> log dict's getItem("B90") --> {"B90 blue"}
>
> ======================================================================
>
> If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first <http://applemods.sourceforge.net/getstarted.html>. Run the Loader installer, then download and add the Types library to the ASLibraries folder. You can use the LoaderWizard applet to generate the library loading code to paste at the top of your script.
>
> HTH
>
> has
> http://freespace.virgin.net/hamish.sanderson/
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden