make a variable = to more than one possibility

I thought this might work

set Jtype to {“BW”, “ER”, “HR”, “HB”, “JM”, “NW”, “RI”, “SC”, “WA”, “WW”}

set fileMatrix to {¬
{folderName:“BHS”, prefixes:{(“BH70” & Jtype), (“SM70” & Jtype), (“AL70” & Jtype), (“BH11” & Jtype)}}, ¬

I was hoping my prefixes would then equal, BH70BW, BH70ER, BH70HR etc.?

How could this be achieved?

Hi,

you can do it this way


set fileMatrix to {¬
    {folderName:"BHS", prefixes:{("BH70" & item 1 fo Jtype), ("SM70" & item 2 of Jtype), ("AL70" & item 3 of Jtype), ("BH11" & item 4 of Jtype)}}, ¬

Hello.

I see Stefan has answered it, but I came up with something in the mean time, maybe I have misunderstood something.

 -- I think this might work

set M to {}
set suffixes to {"BW", "ER", "HR", "HB", "JM", "NW", "RI", "SC", "WA", "WW"}

repeat with jtype in suffixes
	set end of M to {("BH70" & jtype), ("SM70" & jtype), ("AL70" & jtype), ("BH11" & jtype)}
end repeat

It gives output like this in a matrix-like row first list of lists.

Thanks for responding Stefan, this give the result

{{folderName:“BHS”, prefixes:{“BH70BW”, “SM70ER”, “AL70HR”, “BH11HB”}},

McUsrII this output is more what I need, although I need it to fit in with the script I use already as I need to apply it to all the folders…

set Jtype to {"BW", "ER", "HR", "HB", "JM", "NW", "RI", "SC", "WA", "WW"}

set fileMatrix to {¬
	{folderName:"BHS", prefixes:{("BH70" & Jtype), ("SM70" & Jtype), ("AL70" & Jtype), ("BH11" & Jtype)}}, ¬
	{folderName:"Bu", prefixes:{"BU40", "BU11"}}, ¬
	{folderName:"Ca", prefixes:{"CW"}}, ¬
	{folderName:"Da", prefixes:{"ES20", "AM20"}}, ¬
	{folderName:"Di", prefixes:{"DV25", "DV11"}}}

Hello.

I can’t deduct any pattern of anything here. Is there a pattern, or is it so, that one folder has its unique set of prefixes?

If each folder has a unique set/combination of prefixes, then I suggest you hard-code it.

Basically all of these are the beginning of files that, belong to the folder “BHFolder”
The suffix is the part thats the same on each of the 5th and 6th Character.

Was hoping to avoid the had coding as there are a lot to fill out. :slight_smile:

(BH70BW, SM70BW, AL70BW, BH11BW)
(BH70ER, SM70ER, AL70ER, BH11ER)
(BH70HR, SM70HR, AL70HR, BH11HR)
(BH70HB, SM70HB, AL70HB, BH11HB)
(BH70JM, SM70JM, AL70JM, BH11JM)
(BH70NW, SM70NW, AL70NW, BH11NW)
(BH70RI, SM70RI, AL70RI, BH11RI)
(BH70SC, SM70SC, AL70SC, BH11SC)
(BH70WA, SM70WA, AL70WA, BH11WA)
(BH70WW, SM70WW, AL70WW, BH11WW)

Hello.

Please try to produce a complete list of folders, and the suffixes that are to go into each of them. -Or a rule set of combinations for each of the folders in a kind of matrix form, like prefix list and a suffix list, and then I’ll see what I can do about it. I’ll be busy for the rest of the evening, so if there aren’t any other takers in the mean time, you’ll have it by tomorrow, if I can sort it out. :slight_smile:

Hello.

Maybe you can use the handler below, and create a list of prefixes for each folder individually. It is ok to pass lists with prefixes and suffixes to it. Remember that the number suffixes governs the number of items that are created, and that the number of items returned is prefixes * suffixes, but you probably knew that. -It is just to explain how it works, just in case. :slight_smile:

(*
combines two lists of prefixes, and suffixes (secondPart )
into a list of combinations.


*)
set suffixes to {"BW", "ER", "HR", "HB", "JM", "NW", "RI", "SC", "WA", "WW"}
set prefixes to {"BH70", "SM70", "AL70", "BH11"}

set prefixesList to combine(prefixes, suffixes)

log prefixesList

set fileMatrix to {¬
	{folderName:"BHS", prefixes:prefixesList}}

log fileMatrix


on combine(firstPart, secondPart)
	set m to {}
	script o
		property l : firstPart
		property m : secondPart
	end script
	repeat with i from 1 to (count o's m)
		repeat with j from 1 to (count o's l)
			set end of m to (item j of o's l & item i of o's m)
		end repeat
	end repeat
	return m
end combine

Hello.

I’m just guesssing what you are after here, but this is an attempt.

set suffixes to {"BW", "ER", "HR", "HB", "JM", "NW", "RI", "SC", "WA", "WW"}
set fileMatrix to {¬
	{folderName:"BHS", prefixes:combine({"BH70", "SM70", "AL70", "BH11"}, suffixes)}, ¬
	{folderName:"Bu", prefixes:combine({"BU40", "BU11"}, suffixes)}, ¬
	{folderName:"Ca", prefixes:combine({"CW"}, suffixes)}, ¬
	{folderName:"Da", prefixes:combine({"ES20", "AM20"}, suffixes)}, ¬
	{folderName:"Di", prefixes:combine({"DV25", "DV11"}, suffixes)}}
(* Provisional code for displaying the result nicer follows ... *)
set logtxt to ""
repeat with aRow in fileMatrix
	try
		text 0 of aRow
	on error e
		set ofs to offset of "{" in e
		set logtxt to logtxt & (text (ofs + 1) thru -2 of e) & return
	end try
end repeat

display dialog logtxt
(*
combines two lists of prefixes, and suffixes (secondPart )
into a list of combinations.
*)


on combine(firstPart, secondPart)
	set m to {}
	script o
		property l : firstPart
		property m : secondPart
	end script
	repeat with i from 1 to (count o's m)
		repeat with j from 1 to (count o's l)
			set end of m to (item j of o's l & item i of o's m)
		end repeat
	end repeat
	return m
end combine

Thanks for your help that did work, although when it gets passed over to the rest of the script it starts looking back for the prefix

repeat with aPrefix in prefixes of matrixItem -- look for files

So now opted for the Hard coding, I’m sure I can find that coding useful for other scripts though.

Many Thanks
Matt

set suffixes to {"BW", "ER", "HR", "HB", "JM", "NW", "RI", "SC", "WA", "WW"}

set BH_prefixes to {"BH70", "SM70", "AL70", "BH11"}
set BU_prefixes to {"BU40", "BU11"}
set ES_prefixes to {"ES20", "AM20"}
set DV_prefixes to {"DV25", "DV11"}
set DJ_prefixes to {"DJ30", "DJ11"}
set GT_prefixes to {"GT55", "CC55"}
set FR_prefixes to {"FR10", "FR11", "FR17"}
set MA_prefixes to {"MA65", "MF65", "FI65", "MC65", "MH65", "MB65"}
set TM_prefixes to {"TM15", "TM11"}
set WA_prefixes to {"WA35", "WA11"}
set WE_prefixes to {"WE57"}


set BH_prefixesList to combine(BH_prefixes, suffixes)
set BU_prefixesList to combine(BU_prefixes, suffixes)
set ES_prefixesList to combine(ES_prefixes, suffixes)
set DV_prefixesList to combine(DV_prefixes, suffixes)
set DJ_prefixesList to combine(DJ_prefixes, suffixes)
set GT_prefixesList to combine(GT_prefixes, suffixes)
set FR_prefixesList to combine(FR_prefixes, suffixes)
set MA_prefixesList to combine(MA_prefixes, suffixes)
set TM_prefixesList to combine(TM_prefixes, suffixes)
set WA_prefixesList to combine(WA_prefixes, suffixes)
set WE_prefixesList to combine(WE_prefixes, suffixes)




set fileMatrix to {¬
	{folderName:"BHS", BH_prefixes:{BH_prefixesList}}, ¬
	{folderName:"Bu", BU_prefixes:{BU_prefixesList}}, ¬
	{folderName:"Da", ES_prefixes:{ES_prefixesList}}, ¬
	{folderName:"Di", DV_prefixes:{DV_prefixesList}}, ¬
	{folderName:"Do", DJ_prefixes:{DJ_prefixesList}}, ¬
	{folderName:"In", GT_prefixes:{GT_prefixesList}}, ¬
	{folderName:"Fr", FR_prefixes:{FR_prefixesList}}, ¬
	{folderName:"Ma", MA_prefixes:{MA_prefixesList}}, ¬
	{folderName:"To", TM_prefixes:{TM_prefixesList}}, ¬
	{folderName:"Wa", WA_prefixes:{WA_prefixesList}}, ¬
	{folderName:"WE", WE_prefixes:{WE_prefixesList}}}

Hello.

I don’t know if this helps, but the idea was that you’d dereference the Matrix in a loop like this, so that you get access to the prefixes as a list, and the folder name as a list.

set somePath to "Some HD:SomeUser:someFolder" as alias
tell application "Finder"
	repeat with aRow in fileMatrix
		set theFol to folderName of aRow
		
		set fprfx to prefixes of aRow
		repeat with curprf in fprfx
			set flist to (every file of folder theFol of somePath whose name begins with fprfx)
			-- processing or whatever
		end repeat
	end repeat
end tell

This code is just mocked together to show you what I mean, and I haven’t tested any part of it, than merely seeing that I indeed got out the foldername and the list of prefixes.

This is working for me!

When I had the previous script I was using a “wildcard” so that all items that don’t fit the above go to another folder,

{folderName:"2_do_Mik", prefixes:{""}}}

However this didn’t always work I figure it would be good to use all the data above and use a line similar to those files that are not in {all prefixes}

not sure how I would incorporate that into the script, of to have a practice.

Hello.

The inverse operation is harder, or at least takes a lot more time to do, since you then will have to check each and every file, for membership in one of the patterns.

A better approach would be to check the modified date of the file, if your script moves or does any thing to your file.

Then you could have finder return a list with files, that haven’t been changed since before you ran the script.