# Trying to wrap my head around julia's file handling (still!)

**URL:** <https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379>\
**Category:** New to Julia\
**Created:** [August 26, 2022, 11:59am UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379 "2022-08-26T11:59:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![skypuppy](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skypuppy](https://discourse.julialang.org/u/skypuppy)\
**Post date:** [August 26, 2022, 11:59am UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379/1 "2022-08-26T11:59:41Z")

</div>

How would one start thinking about this task:  
Goal: search all files in the entire filesystem for particular strings

1. find all files that contain “somestring”  
for example, “dog” and or “Schnauzer” – case insensitive
2. 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.
3. repeat step 2 until all files have been traversed.
4. 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

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [August 26, 2022, 12:33pm UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379/2 "2022-08-26T12:33:58Z")

</div>

Can you say more about what’s causing you trouble with an individual step like 1? What have you tried? What is blocking you?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [August 26, 2022, 1:55pm UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379/3 "2022-08-26T13:55:11Z")

</div>

For 1. you need the function `readdir` or `walkdir` and `occursin`. See [Filesystem · The Julia Language](https://docs.julialang.org/en/v1/base/file/#Base.Filesystem.walkdir)  
For 2. probably `Base.stat(file)` [Filesystem · The Julia Language](https://docs.julialang.org/en/v1/base/file/#Base.stat)

Not sure if there is a bullet proof way to figure out if a file is binary.

---

<div class="post-metadata">

**Author:** ![skypuppy](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skypuppy](https://discourse.julialang.org/u/skypuppy)\
**Post date:** [August 26, 2022, 4:41pm UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379/4 "2022-08-26T16:41:42Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![skypuppy](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skypuppy](https://discourse.julialang.org/u/skypuppy)\
**Post date:** [August 26, 2022, 4:43pm UTC](https://discourse.julialang.org/t/trying-to-wrap-my-head-around-julias-file-handling-still/86379/5 "2022-08-26T16:43:25Z")

</div>

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.
