Get 1 file at a time in a list of files (with "repeat")

Hello,

I seem to have issues working with lists and repeats here.
I have a variable called thisFolder, which contains a list of paths to the files in my table view.

For some reason I can’t get each file separately to do actions on them.
Here is my code:

set theseItems to thisFolder 
(* if I have a dialog display the variable "thisFolder", it contains paths in the form 
"Mac HD:Users:BS0D:Desktop:cfdt:mysample2.phpMac HD:Users:BS0D:Desktop:cfdt:my-sample.php" *)
  repeat with i from 1 to count of theseItems
	set thisitem to alias ((thisFolder as text) & (item i of theseItems))
	--display dialog thisitem
	set itemInfo to info for thisitem
	    if subOk and folder of itemInfo is true and package folder of itemInfo is false then
	        processFolder(thisitem, true)
	      else if (alias of itemInfo is false) and (the name extension of itemInfo is in extensionList) then
	        processItem(thisitem)
	   end if
   end repeat

Then I get the following error :

I know of course there is something really wrong with my code here, but I cannot find the right syntax to get items separately for life of me !
I don’t understand why I can’t have each item separately and why in the error message I get the “M” at the end of the paths…

Can anyone help please ?

Thanks in advance…

OK, if I do this instead :

set theseItems to thisFolder as string as alias

I do not get the “M” at the end of the path… that’s one thing but it doesn"t solve my problem about getting each item one by one.

Please help !

If theFolder contains a list of paths, then this cannot work


alias ((thisFolder as text)

because thisFolder as text concatenates the items of the list depending on AppleScript’s text item delimiters, an the alias coercion will fail

Ok, I just realized and I took it out.

So do you have any idea how I can separate the items to process them one by one ? I’m getting so confused with the list thing …

changing this line should be sufficient


set thisitem to (item i of theseItems) as alias

Nope, still gives me an error message :

GgrrrrRrRrRR >:

then the question is: Where comes the “M” from, that occurs before the code snippet

I have no clue, I have dialogs everywhere and it seems that it occurs right in this routine.

Dont know what else to do really…

You can ignore the error with a try block


set theseItems to thisFolder
(* if I have a dialog display the variable "thisFolder", it contains paths in the form 
"Mac HD:Users:BS0D:Desktop:cfdt:mysample2.phpMac HD:Users:BS0D:Desktop:cfdt:my-sample.php" *)
repeat with i from 1 to count of theseItems
	try
		set thisitem to (item i of theseItems) as alias
		--display dialog thisitem
		set itemInfo to info for thisitem
		if subOk and folder of itemInfo is true and package folder of itemInfo is false then
			processFolder(thisitem, true)
		else if (alias of itemInfo is false) and (the name extension of itemInfo is in extensionList) then
			processItem(thisitem)
		end if
	end try
end repeat

but it would be better to find the cause of the “M”-error

Yeah, sure it doesnt freeze if I ignore the error, but of course it doesnt do what I want it to do, so there’s no point.

I absolutely need to find why I get this error

Hello again,

I need a clear explanation of what I can do here, because my problem is still not solved!

So what I do in my app is:

  • drop items on a table
  • display their paths (the path of each item in a different row)
  • get those paths and put them at the end a variable (called itemList{} or something)

→ then I want to process each item one by one, but I can’t seem to get the paths from that variable correctly, as the app gives me that error about the files not existing.

How would you go about doing that ? because my code, the one above, just does NOT work !

thanks

The error occurs probably in one of the lines above

OK, I’m not on my mac right now (at work), but I’ll post my code tonight. It’s possible that the error occurs when I
get those paths and put them at the end of the variable …

Mind you, everything works perfectly when I follow those same steps in the other tabs of my app…

EDIT | actually I’m pretty sure that the error ocurrs when I try to set “theseItems” in the repeat procedure as follows:

set theseItems to thisFolder -- thisFolder contains all the paths, but I'm sure I need to do this differently
repeat with i from 1 to theseItems
set thisitem to --blah blah
-- blah blah
end repeat

-- here is the processing of my items

No, the error occurs, because the list thisFolder contains an element which is no valid path.
The repeat loop is correct

Well I think I should actually add something like :

set theseItems to thisFolder -- AS SOMETHING ? as string ? alias ? I don't know, these things confuse me!

Like I said, thisFolder contains paths in the following form :

I don’t know if this looks right, but thats what it says if I do a “display dialog thisFolder”
So first, is that what it should look like ?
And if so, what would be the best way to loop through those items?

Somewhere in your code before the display dialog statement you have a as text coercion, which coerces the path list to a string (text item delimiters are {“”} at that moment). This is the crucial line

OK, problem solved … this is soooo stupid !

I actually had to set theseItems to something other than thisFolder, I was calling the wrong variable (yeah, my script is long and tedious – about 2,000 lines, so in spite of commenting as much as I can, I kind of get confused)

Thanks for your help and advice anyway, Stefan.

Best.