[Closed] compare filepaths to pattern
There is a lot of scripts for search missing assets but when it comes to simple file-names like 1.jpg, etc, those scripts usually just take
first encountered matching pattern as your missing file when in practice I have many files at this same name and I almost never can proper track those missing files in this way.
Usually files are missing because file with all it sub-folders was moved to different location or to different drive.
So, in case of many files matched to my searching pattern I’m trying to choice not only those which have identical name but also it paths.
And now is my question.
I was wondering is it possible to compare array with couple of file-name paths which fit to my file-name but have different paths to my pattern file-name paths, this is example:
My pattern: “d:/work/pkp_trains/final/roof.png”
Example array with found resoults: array my_files=#(d:/temp/pkp_trains/final/roof.png, d:/roof.png, d:/textures/temporary/final/roof.png)
In this case the most similar is d:/temp/pkp_trains/final/roof.png.
I was wondering is it possible by s using some smart dotnet function or other max way before I start to take this apart which is
what I’m currently doing right now?
most popular, fast enough, and easy to implement is Levenshtein distance
here is complete c# code http://stackoverflow.com/questions/6944056/c-sharp-compare-string-similarity
So it must be rip apart anyway I was thinking about something less pain-full.
like always thank you, maybe there is something less popular and more maxscript-isch. My c# understanding is 0.0. I bet It`s easy to implement but I’m not even close with this one. I back to my fiddle.
unfortunately there is no maxscript it this list rosettacode.org/wiki/Levenshtein_distance
but you can pick the most familiar for you.
of course i can post here a maxscript version. but it will be too easy.
I know you a little bit so I don`t expect you to make it so easy:) . Translating this on maxscript will take me a day without guarantee so I write my own code for this. I already have blueprint. Thanks anyway.
It’s very kind of You, script works really very well however I was running out of time with this one back then and I already wrote it on my won, not as precise and elegant as your but still work well enough to make job done. It work on little bit different assumptions:
code:
— array with filenames to search the most similar to pattern
my_files=#(“textures/head.jpg”,“robocop/textures/head.jpg”,“d:/work/robocop/textures/head.jpg”,“ddd:/wdodrkdwq/robdqwocdqop/textudqdqwres/headqwdqwdqwdqwdqwdqd.jpg”)
numbers=#() – temporary array for numbers to compare numbers with items
—- searching pattern
s1=“d:/work/robocop/textures/head.jpg”
score=0
for b=1 to my_files.count do — loop by by all items from my_files array
(
score=0
for a=1 to s1.count do — loop by all letter in item and compare with pattern
(
trimedstring = substring s1 a (a+3)
—– compering trimed string with pattern
comparestringa=trimedstring
comparestring=”“+comparestringa+”“
credit=matchPattern my_files[b] pattern:comparestring– returns true
if credit==true then score+=1
)
append numbers score
)
—–check greatest number
aa=finditem numbers (amax numbers)
—- associate path with greatest number
print my_files[aa] – <— item I`m looking for