dersar00
How I can listen folder changes?(watch folder)
Hello, for example I need to move file to other folder if it falls into some watched folder, how I can do it?
I find some script, but it didn’t work well, maybe any idea?
Finded script:
defmodule Daemon do
use GenServer
def start_link(opts \\ %{}) do
GenServer.start_link(__MODULE__, opts, [])
end
def init(args) do
# TODO pass dirs as config
IO.puts "\n\t\tSTART DAEMON\n"
{:ok, watcher_pid} = FileSystem.start_link(dirs: ["/home/vagrant/datarama/datarama-import/public/uploads/daemon_store"])
FileSystem.subscribe(watcher_pid)
{:ok, %{watcher_pid: watcher_pid}}
end
def handle_info({:file_event, watcher_pid, {path, events}}, state) do
IO.inspect(events)
IO.inspect(path)
case List.last(events) do
:removed ->
IO.puts "REMOVED"
:created ->
IO.puts "CREATED"
IO.inspect(path)
:modified ->
IO.puts "MODIFIED"
_ ->
IO.puts "NONE"
end
{:noreply, state}
end
def handle_info({:file_event, watcher_pid, :stop}, state) do
{:noreply, state}
end
end
Most Liked
Nicd
It seems from your code example you may already be using it, but check https://hex.pm/packages/file_system - it has worked well for me. If you have specific problems with it, can you specify them in more detail?
2
Popular in Questions
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New







