how can i search my entire directory for an email ...
# cfml-general
s
how can i search my entire directory for an email address ending with @calendar-ca and list all the files where those changes are
m
the normal questions will be asked: 1.) What is your directory stored in. 2.) What is your API to access your directory?
☝️ 1
s
api/
there is no api here
r
to clarify here, @Simone, are you asking how to do this within an application written in CFML?
m
I am sure what ever your using for directory storage there is some sort of API unless it is a flat file then you have to write your own accessors and probably move it to something else. Examples of directory storage: • LDAP • Database • Active Directory
s
its a cfml directory and has nested directors, all i need to search that phrase and list down all the files in an array where it is happening and how many times
m
So the question is how to do a recursive search of a file system directory of every file that has a name that ends in a certain phase?
m
Many IDEs can do this; what are you using?
s
i tried this
but after my dump of filecontent on line 18, i am not sure why its not working properly, i want to list down how many times that charList happened
like 5 times in a file, so it show me 5 times
m
I haven't tested this... so I don't know if this works or if there is some tweaking but this is what i would do in this situation... I would always write such a thing as a function take away any display or anything like that...keep it down to pure logic. And then try it out... here is what mine looked like... https://trycf.com/gist/2c21dfe7e222502b014f20b00458e75d/lucee5?theme=monokai
s
interesting but i wonder how it is outpuuting the dump fo the files, the cfm code, that is what i am looking around, it should just give file name an counts of that text howmany tims not, the entire cfm file
figured out, working on updating accordingly to ake it work
i am using cf2021, so i changed the foreach to ArrayEach but i am getting issues; ArrayEach(files,*function*(itm){ Array happening on ArrayLen(matches) where it tries to chck java.lang.integer cannot be used with array, and does it also list the file names where it happens or just counts
m
yep i see my error my ReFindNocase wasn't long enough and i need each instead of forEach... ran with fake data to see it work...
Copy code
files.each((itm) => {
            var tmpContent = FXileRead(itm);          
            var matches = ReFindNoCase(x, tmpContent,1, false, "ALL");
          
            if ( IsArray(matches) and ArrayLen(matches) > 0 )
            {
                strCounts[x][itm] = ArrayLen(matches);
            }
});
https://trycf.com/gist/714a89eb5febba0608baba4179556c18/acf2021?theme=monokai