# Need resource for worked examples for simple things

**URL:** https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579
**Category:** General Usage
**Created:** [February 1, 2022, 3:31pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579 "2022-02-01T15:31:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [February 1, 2022, 3:31pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/1 "2022-02-01T15:31:09Z")

</div>

Hi all  
working my way through the high level concepts and hitting a stumbling block. My first inclination is to look at a simple worked example and figure out what I don’t understand. So an example is that I wanted to look into [FileWatching](https://docs.julialang.org/en/v1/stdlib/FileWatching/#lib-filewatching) so I could monitor a folder. So the documentation gives you the basics BUT doesn’t seem to cover how the filename is returned. Here is my REPL example where I updated a text file called tst.tst.

```julia
julia> using FileWatching
shell> pwd
/home/dave/tontine_2022/just_messing

julia> watch_folder( "/home/dave/tontine_2022/just_messing", 60)
".goutputstream-RR4KG1" => FileWatching.FileEvent(true, false, false)

julia> 

```

so the returned values should have been:  
filename : but I got .goutputstream-RR4KG1"  
event ; `changed` , `renamed` , and `timedout` : FileEvent(true, false, false)

So to my julia ignorant eye this tells me that “.goutputstream-RR4KG1” was changed but not how to get the filename. So what am I missing?

Also I would like to have a link to a resource where this is covered in an example. I tried searching discourse but FileWatching.watch\_folder didn’t return anything.

thank you

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [February 1, 2022, 4:23pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/2 "2022-02-01T16:23:06Z")

</div>

I suspect that it is working as expected and  
`.goutputstream-RR4KG1` is the name of the file which changed. It’s created by Gnome

I would put it in a loop

```julia
    while true
        println(watch_folder( "/home/dave/tontine_2022/just_messing", 60))
   end

```

I did that on my /home and got two events for echo \> hi

```julia
"hi" => FileWatching.FileEvent(true, false, false)
"hi" => FileWatching.FileEvent(false, true, false)

```

The docs say

> This will continuing tracking changes for `path` in the background until `unwatch_folder` is called on the same `path` .

So every time you call it, it will pop the last entry from `inotify` or whatever the local platform event montior is.

Julia itself doesn’t actually do the monitoring.

On Linux it uses this

[https://www.man7.org/linux/man-pages/man7/inotify.7.html](https://www.man7.org/linux/man-pages/man7/inotify.7.html)

---

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [February 1, 2022, 6:27pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/3 "2022-02-01T18:27:19Z")

</div>

Thank you for the excellent reply.

I had done the same as you but created a file in Nautilus by RMC to see what would happen, then added a few lines to it and renamed it to “the tes” saved it and got the 4 events below. I am not STILL not certain what they are.

**When you say they are from gnome how can I exclude them from the processing as they don’t seem relevant.**

Please remember my OP was how do I find more examples regarding FileWatching. If you can show me where to find that info for this then I “hope” there is more for other areas. I can’t find anything that does the simple stuff like this.

```julia
julia> using FileWatching

julia> while true
               println(watch_folder( "/home/dave/tontine_2022/just_messing", 60))
          end
"Untitled Document" => FileWatching.FileEvent(true, false, false)
"Untitled Document" => FileWatching.FileEvent(true, false, false)
"the tes" => FileWatching.FileEvent(true, false, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(true, false, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(false, true, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(false, true, false)
".goutputstream-ZE9QG1" => FileWatching.FileEvent(true, false, false)
"the tes" => FileWatching.FileEvent(true, false, false)

```

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [February 1, 2022, 6:59pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/4 "2022-02-01T18:59:44Z")

</div>

```julia
while true
    filename, event = watch_folder("/home/dave/tontine_2022/just_messing", 60)
    if !startswith(filename, ".goutputstream")
        println(filename, " => ", (event.changed ? "changed" :
                                   event.renamed ? "renamed" :
                                   event.timedout ? "timed out" :
                                   error("Unknown event"))
                                   )
    end
end

```

This will both skip the `.goutputstream` files, and print the file event as a readable string.

For more examples about using FileWatching, you could try this [SourceGraph search](https://sourcegraph.com/search?q=context:global+lang:Julia+FileWatching&patternType=literal) of code that uses the package (though you’ll have to do a bit of digging yourself to see where exactly the functions are being used in the code).

Edit: changed github search to SourceGraph, results seem much better there

---

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [February 1, 2022, 7:22pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/5 "2022-02-01T19:22:07Z")

</div>

thanks digital the SourceGraph is much better. I’m coming from the python world where the examples are plentiful and clarity is king 🙂

**Thanks for the code but doesn’t it seem odd to you that it has to be done this way?**

I can’t be the first to come across this UNLESS I don’t have the correct julia mental model. Which others in this forum have suggested.

All I wanted to do was monitor a folder for rational events and when they happen take resultant action. Finding the [file events docs](https://docs.julialang.org/en/v1/stdlib/FileWatching/#lib-filewatching) was the easy part. Figuring out how to code it was also easy

```julia
while true
      (file, event) = watch_folder(dir, 1)
      if event.changed
         figure out what to do

```

but then all these strange filenames start appearing and have to be handled. So what started out simply, monitor a folder and when something changes tell me the name of the the thing and what happened becomes something more.

@lawless-m did a great job pointing out where they come from but it’s further down the rabbit hole than I like. To follow up on his observation that it was gnome related I found this that explains it nicely  
[where do goutputstream files come from](https://github.com/mate-desktop/caja/issues/1439) which offers the solution to ignore them and try again a few seconds later which seems to be the case.

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [February 1, 2022, 7:33pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/6 "2022-02-01T19:33:58Z")

</div>

I agree with the general point that more worked examples would be good - Julia community is making good progress towards catching up with Python or other languages that have had decades of writing examples, blog posts, tutorials, etc., and there’s still work to be done.

But in this case, the rabbit hole has nothing to do with Julia; any library in any language that does file watching will report the same things, and will need the same kind of filtering. Julia is reporting back what changed in the filesystem - just as we ask it to, and just like any other language will - and it cannot by itself decide what is and isn’t an important event to report: that’s for us to decide depending on our use case.

---

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [February 1, 2022, 7:44pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/7 "2022-02-01T19:44:30Z")

</div>

hi @digital_carver  
julia is 10 years old isn’t it? This functionality seems to be pretty basic and I would have thought others would have covered it. So in this case it’s a set of temporary files that get created momentarily then disappear, yes it can be coded out but shouldn’t watch\_folder have a argument that considers that so we don’t have to. If julia knows we are using gnome then…

**NOW I am not being critical, it’s just to a noob like me this isn’t tip top. I don’t code for a living and that’s why python is such a great choice.**

this is NOT my code but makes my point. Easy to locate, helps to make me a better “coder”, gets the job done and I wonder how it would handle .goutputstream. Seems it handles vim temp files pretty well and it’s clear what is happening.  
``

[how to scan file events in python](https://laptrinhx.com/how-to-create-a-watchdog-in-python-to-look-for-filesystem-changes-4123930011/)

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [February 1, 2022, 10:33pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/8 "2022-02-01T22:33:14Z")

</div>

That link is just someone’s blog, someone just like you. Someone who came across some library code, wrote a few bits with it until it worked and then wrote a blog post about it. Today could be the day you write a blog post about `FileWatching` in Julia.

🕶

---

<div class="post-metadata">

### Author: ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)
#### Post date: [February 1, 2022, 10:56pm UTC](https://discourse.julialang.org/t/need-resource-for-worked-examples-for-simple-things/75579/9 "2022-02-01T22:56:23Z")

</div>

OH that I was such a great coder 🙂 Right now I’m trying to just get to get off to a sensible start. Something I did NOT do with python. All my code was mindless hack jobs cobbled together to just get the job done. The only time I took a step back was with pandas. WOW that was FUN!!! I learnt a LOT and was STUNNED the small amount of code I had to write to get complex things done. I am hoping julia will be the same experience once I get into the swing of things. It’s not too bad it’s just stuff like this that trips me up. Thanks for all your great help.
