Filter in Find on file/folder names

Hi all

I have try some things but no luck, I hope you guys can help me

I have this script for example

set streamEditorCommand to " | tr [/:] [:/] "
set streamEditorCommand to streamEditorCommand & " | sed -e " & quoted form of (" s.:." & (POSIX file “/” as string) & “.” )
do shell script “find -E ‘/Users/mvp/Desktop’ -iregex ‘./[^~][^/]\.xlsm$’ -maxdepth 3” & streamEditorCommand without altering line endings

It get the xlsm files from my desktop and a few levels down, this is working OK.
But I want to add a filter because it now filter on the name column by default I think.

This means that the files from each folder are not together, so I think I am looking for a way to filter on Type
so I get the files together from the desktop and subfolders

I hope I am clear in what my problem is

Thank you

Hello.

Try this. :slight_smile:


set streamEditorCommand to " |  tr  [/:] [] "
set streamEditorCommand to streamEditorCommand & " | sed -e "  & quoted form of (" s.:."  & (POSIX file "/"  as string) & "." )
do shell script " ( find -E '/Users/mvp/Desktop' -iregex '.*/[^~][^/]*\\.xlsm$' -maxdepth 3" & streamEditorCommand & " )  | sort " without altering line endings


Hi McUsr

Not I get the same results now, I think I must add some parameter to Sort.

I simple want the files from the desktop first and then the files from and each sub folder.
So the files from each folder are after each other in the list

Thanks for your reply

Hello.

I modified your original one, to move the files from desktop, up front, from there onwards, the folders are following directly.


set streamEditorCommand to " |  tr  [/:] [/:] "
set streamEditorCommand to streamEditorCommand & " | sed -e " & quoted form of (" s.:." & (POSIX file "/" as string) & ".")
do shell script " find -E '/Users/mvp/Desktop' -iregex '.*/[^~][^/]*\\.xlsm$' -maxdepth 3" & streamEditorCommand & " | tee /tmp/mvp | ( sed -n '/\\/Users\\/mvp\\/Desktop\\/[^/]\\{1,\\}$/p' |sort -f ;  cat /tmp/mvp | sed -n '/\\/Users\\/mvp\\/Desktop\\/[^/]\\{1,\\}$/ !p' |sort -f ) " without altering line endings

Edit:

It now ignores case when sorting.

Thanks again for your reply

The files on the desktop are together now but the files from the subfolders not

Not so easy

That is funny, they are at my place!

Try the one above your last post, I did try a couple of things, but that one should keep the files collated by folder, if not, then I really don’t know what to do about it.

Hi McUsr

It is working OK when I set level to 2 but if I use 3 (folders in the subfolders it go wrong)

Well, I can’t help you with that, I just tested it with a maxdepth of 4, and it still works for me.

I wonder if you have any accented characters in your file name? The fix for that would be to enter:

 export LC_COLLATE=nl_NL.UTF-8 ;

as a prequel in the do shell script (with the semi-colon (“;”)).