How would one start thinking about this task:
Goal: search all files in the entire filesystem for particular strings
- find all files that contain “somestring”
for example, “dog” and or “Schnauzer” – case insensitive
- into the results file, place the file name, location of the occurrence(s) offset from the beginning of the file, the files last touched date, whether the file is binary or text,and maybe size of the file.
- repeat step 2 until all files have been traversed.
- close the output file.
For some reason, I can’t seem to figure out how this can be done.
Thanks for any thoughts and help!
David
Can you say more about what’s causing you trouble with an individual step like 1? What have you tried? What is blocking you?
1 Like
For 1. you need the function readdir
or walkdir
and occursin
. See Filesystem · The Julia Language
For 2. probably Base.stat(file)
Filesystem · The Julia Language
Not sure if there is a bullet proof way to figure out if a file is binary.
Only thing I can think of is the way I used to do it, scan for ASCII/non-ASCII and if any non-ASCII is found, mark it as binary.
I have studied on the filesystem functions and don’t recall “occursin.” Sounds like a cool tool!
Understanding and begin thinking in the peculiar way Julia conceptualizes these things, esp as compared to ‘C’ and Python.
Of course, the stroke 2 years ago --might-- be a contributing factor, I don’t know.