Quoted form and file path problem

Hi there

I am stuck on a small portion of script. The portion concerned is intended to get a list of files inside a named folder - “EyeTV Encoded”, without using Finder or System Events.

Here is the code:

set thefolderfromlist to ((path to current user folder) as text) & "Movies:EyeTV Encoded:"
set thefolderfromlist to quoted form of POSIX path of thefolderfromlist
set allList to paragraphs of (do shell script "find " & thefolderfromlist & " -type f -maxdepth 1 | grep -v .DS_Store | grep -v .localized | grep -v .BackupIcon.icns |grep -v Icon |sed 's:" & thefolderfromlist & "/::'")

When I run the script, I get the following error:

The script works if I rename the folder “EyeTVEncoded”. So the problem is where there is a space in the folder name. I thought that using the command “quoted form” was the solution to this problem. But apparently not.
Anybody see where the error lies?

On a side note, I am trying to replicate the Finder command:

 Set allList to every item of folder thefolderfromlist

The additional grep commands are intended to achieve this, but it is a bit trial and error for me as I do not know what files a Finder search would reveal that the bare shell script would NOT reveal. Any tips on that score would be welcome as well.

Hi,

too complicated, using Spotlight to search for the kind is easier and faster, if the movies are not mpg4 movies, you have to adjust the kMDItemKind parameter

set thefolderfromlist to quoted form of (POSIX path of (path to movies folder) & "EyeTV Encoded:")
set allList to paragraphs of (do shell script "/usr/bin/mdfind -onlyin " & thefolderfromlist & " 'kMDItemKind = \"MPEG-4 Movie\"'")

Thanks, Stefan

No error now. But I can’t get it to produce a list after playing about with kind.
Basically, I am not fussed about the kind of file that may be in the folder (other than avoiding invisible, .ds store and any other files that Finder would not not normally see). Can you use wildcards somehow? Sorry, shell scripting in detail is somewhat beyond me.

Thanks

Try this script to determine the kind


set inputFile to quoted form of POSIX path of (choose file with prompt "Select file" without invisibles)
set a to (do shell script "mdls " & inputFile & "| grep kMDItemKind")
display dialog a

Thanks. I had the right kind. But apparently the colon at the end of “Eye TV Encoded:” needed to be removed. Have done that and results are coming in. Will play and revert if I get stuck again.

Many thanks

Stefan

Hope you can help on the next issue encountered. I have it all working but want to extract the filename from the list item. I have done this:

on extractname(fName)
	set nbr to the offset of "/" in (reverse of characters of fName as string)
	if nbr > 0 then
		tell fName to set fName to text -(nbr - 1) thru -1
	end if
	return fName
end extractname

All works perfectly, EXCEPT when the filename contains an accented character (like "à "). Then, for example, the routine returns “/Abonnement à magazine.pdf” instead of the expected “Abonnement à magazine.pdf”. If two characters are accented, the result includes 2 characters before the name etc etc

What am I missing?

Thanks

this is a perfect job for text item delimiters


on extractname(fName)
	set {TID, text item delimiters} to {text item delimiters, "/"}
	set fName to last text item of fName
	set text item delimiters to TID
	return fName
end extractname

or different approach


set fName to "/Library/Preferences/SystemConfiguration/preferences.plist"
set Nm to name of (info for POSIX file fName as alias)

Option 1 worked perfectly.

Cheers

Stefan

Can I ask you one more thaing.

I have this, adapted from your example:

set listfilesto to paragraphs of (do shell script "mdfind -onlyin " & quoted form of thefolderto & " 'kMDItemFSName = \"*.*\"'")

How do I adapt it to NOT search in subfolders?

Merci

You can’t, your options would be to resort back to a manual find where you can specify min/max-depths or accept all results and since you know the folder it should live in parse out any results containing a subfolder.

Thanks. I went back to the original script I had, which was a manual search. I think I have got it going now, with Stefan’s help on this thread:

set thefolderfromlist to (POSIX path of (path to movies folder) & "EyeTV Encoded")
set allList to paragraphs of (do shell script "find " & quoted form of thefolderfromlist & " -type f -maxdepth 1 | grep -v .DS_Store | grep -v .localized | grep -v .BackupIcon.icns |grep -v Icon |sed 's:" & thefolderfromlist & "/::'")

However, is there anything I am missing to ensure the search result is the same as the Finder would return? I am also conscious of Stefan’s earlier comment that the script was too complicated for what it was attempting to do.

Cheers