Re: How do I create a fileWatcher with an onFileChange event using spawn?

2017-11-12 Thread shuji via Digitalmars-d-learn

On Friday, 25 August 2017 at 21:25:37 UTC, Enjoys Math wrote:



Something like this:


module file_watcher;

import std.concurrency;
import std.file;
import std.signals;
import std.datetime;


void fileWatcher(Tid tid, string filename, int loopSleep) {
auto modified0 = timeLastModified(filename);

while (true) {
modified = timeLastModified(filename);

if (modified > modified0) {
modified0 = modified;
//if (onFileChange !is null)
//onFileChange(receiver);
}

sleep(dur!"msecs"(loopSleep));
}
}


But I'm not sure how to send the onFiledChange event.


@Nemanja Boric I would not recommend calling those APIs on 
Windows because they work on entire directories, not suitable for 
individual files and sometimes  those functions not even work 
when other programs change the files in a non standard way (that 
has happened to me before when editing through a text editor)
@Enjoys Math The way I usually deal with this problem is I save 
the filename, the time and handler function in an associative 
array and loop through when something changes, this way you can 
delete, sort, etc on the map when the files are deleted or so.

Hope this helps a little.


Re: How to detect current executable file name?

2014-07-31 Thread shuji via Digitalmars-d-learn

There is a solution already for this:

http://dlang.org/phobos/std_file.html#.thisExePath

(just for future reference, it's seriously hard to search on 
google)