Replace a string within File Search

I have the following relevance that finds *.url files on the desktop with the string http1.xxxxx.zzzzz.com and http2.xxxxx.zzzzz.com. I need to remove the http1. and http2. from the string.

following texts of firsts "=" of variables whose (it as lowercase contains "http1.xxxxx.zzzzz.com" OR it as lowercase contains "http2.xxxxx.zzzzz.com" ) of (find files "*.url" of ((descendant folders of it; it) of folders "desktop" of folders of folder "C:\users"))

Like you have a string like "foo http1.xxxx.yyyy.zzzz.com bar" and you want it to be foo xxx.yyy.zzz.com bar?

Yes that is correct, and the string has to be modified within several files.

At this point I will be happy to just get a list of the files. I changed the relevance to the following, but it does not pass the syntax check.

find files "*.url" of ((descendant folders of it; it) of folders "desktop" of folders of folder "C:\users") whose (following texts of firsts "=" of variables whose (it as lowercase contains "http1.xxx.zzz.com" OR it as lowercase contains "http2.xxx.zzz.com"))

Does something like this work?

(
  find files "*.url" of (descendant folders of it; it) of of folders "desktop" of folders of folder "C:\users"
)
whose (
  exists (following texts of firsts "=" of variables of it)
  whose (
    it as lowercase contains "http1.xxx.zzz.com" or it as lowercase contains "http2.xxx.zzz.com"
  )
)

Yes that works! The exists is what I was missing. Thanks

Now why doesn’t this work?

pathnames of file ((find files "*.url" of ((descendant folders of it; it) of folders "desktop" of folders of folder "C:\users")) whose (exists (following texts of firsts "=" of variables of it) whose (it as lowercase contains "http1.xxx.zzz.com" OR it as lowercase contains "http2.xxx.zzz.com" )))

That has an extra file on it. The find files inspector already returns a file object, so you can just use pahnames on it directly. Try something like:

pathnames of ((find files "*.url" of ((descendant folders of it; it) of folders "desktop" of folders of folder "C:\users")) whose (exists (following texts of firsts "=" of variables of it) whose (it as lowercase contains "http1.xxx.zzz.com" OR it as lowercase contains "http2.xxx.zzz.com" )))

I got it.

(pathnames of it) of ((find files "*.url" of ((descendant folders of it; it) of folders "desktop" of folders of folder "C:\users")) whose (exists (following texts of firsts "=" of variables of it) whose (it as lowercase contains "http1.xxx.zzz.com" OR it as lowercase contains "http2.xxx.zzz.com" )))

This may be slightly faster:

pathnames of find files "*.url" whose (exists (variables of it) whose (it as lowercase contains "=http1.xxx.zzz.com" OR it as lowercase contains "=http2.xxx.zzz.com")) of (descendant folders of it; it) of folders "desktop" of folders of folders "C:\users"

I also rearranged the relevance a bit to make it flow from right to left a bit better and removed a bunch of unneeded parens.

This is related: https://bigfix.me/analysis/details/2994785


This should be the same, but using descendants instead of find files:

pathnames of descendants whose(name of it as lowercase ends with ".url" AND exists (variables of it) whose (it as lowercase contains "=http1.xxx.zzz.com" OR it as lowercase contains "=http2.xxx.zzz.com") ) of folders "desktop" of folders of folders "C:\users"

descendants seems slower than find files so I wouldn’t switch, but might be useful to know how to do both.