I have written a C program that uses inotify to watch a particular folder. I want to be notified when a new file is created in this folder, or if an existing file was overwritten (i.e. the folder already contains a.txt, and I copy a newer copy of a.txt into this folder, essentially overwriting it).
I am able to generate a notification when new files are added to this folder using the IN_CREATE mask, but I don't get any notification for the second scenario. I've tried IN_MODIFY and IN_ATTRIB, both didn't work.
Is it possible to be notified of the second scenario?
If you overwrite the file you will not get the IN_MODIFY and IN_ATTRIB event. Because, the file is not modified and also the file attributes are not changed. The overwritten is equal to creating a new file. So, You can try that two events with separate.
IN_MODIFY:-
This event is occurred only when the file is modified. To notify this event, you can try to update or remove some contents in the watching list file.
IN_ATTRIB:-
This event is occurred only when the file attribute is changed. Attribute means file meta data. So, If you want to get this event for a file, You can change the file permission in the watching list file.
Make sure, you want to see this event, you have to add the following events in the event list, When your inotify is initialized.
In_MODIFY
IN_ATTRIB
Related
I'm getting the following error:
"The file isn’t compatible with QuickTime Player."
When using this script:
tell application "Finder"
set random_file to some file of entire contents of folder "Movies" of home
open result
end tell
However, I am able to open the file from the finder manually and once I do the script works on just that file. The problem is I have thousands of files and don't want to open each one manually for the script to work again. Have not had this problem with the script in the past.
There are two ways I can think of to approach modifying your script:
Stick with Finder's open command but invoke it fully with its using parameter, which accepts an application file that informs Finder of the application that will be used to open the file. It may sound superfluous given it already tries to open it in QuickTime, and we're not trying to change that, but it's not unwise to see if it does confer a difference in behaviour:
tell application id "com.apple.finder"
tell the folder (path to movies folder) to tell (the ¬
a reference to entire contents) to tell (the ¬
some document file as alias) to set f to it
open f using application file id "com.apple.QuickTimePlayerX"
end tell
Grab the file as you like (really, you ought to be using System Events for this, not Finder, but I'll go with what you had), but then use the open handler of the specific application to open the file:
tell application id "com.apple.finder" to tell the folder (path to movies folder) ¬
to tell (a reference to the entire contents) to tell (some document file) ¬
as alias to set f to it
tell application id "com.apple.QuickTimePlayerX"
activate
open f
end tell
NB. I'm using Monterey, in which both of these two above propositions work appropriately. This doesn't necessarily infer that it will do so in Big Sur, but if they do not, it's worth checking the various app permissions under the different Security & Privacy headings of System Preferences.
I use the shake build system and watch to keep files for a web site current. I cannot understand how to assure that an index file for a directory is changed when a file in the directory changes.
The index file for a directory lists all the files in it with their title and includes a link. From this, a HTML file is eventually produced by the shake process.
It requires reconstruction when one of the indexed files in the directory changes.
For each index file, the set of files indexed are marked as needed but this does not force the index file to be reconstructed when a file in the directory changes. I had expected that this would trigger the reconstruction of the index file if any of the needed files changes. This seems not to be a correct understanding.
What is the most effective method, to force a re-shake of the index file when a file in the directory changes. Is it sufficient to touch the index file to trigger the reconstruction? Or is it better to recompute the conversion of the index.md file to the next step (pandoc) and the following processing steps are then triggered by the shake logic? Or anything else?
I have an URL like
url = "file:D:/inputFolder?move=D:/outputFolder". we are making this url dynamically.
I want to rename the file while moving, So I made it something like this
url = "file:D:/inputFolder?move=D:/outputFolder&fileName=abc.txt". But I think move and fileName do not work together, it is not renaming.
Is there any alternative to do it? Please remember I want with "move" only.
I cannot use .setHeader(..) also.
Thanks,
Hy,
as far as I understand you, your trying to move the file in one single uri.
That is not really how camel works.
The idea of camel is to have a "consumer" and a "producer", where the consumer loads data (e.g. your file) and the producer puts the data somewhere (e.g. save the file into a folder)
That being said, here is what worked for me with a java route:
from("file:/home/chris/temp/camel/in")
.to("file:/home/chris/temp/camel/out/?fileName=test.txt");
The from part configures the folder where camel looks for new files. A few notes on that:
The file component checks the folder each 0.5 sec for new files. This can be changed with the delay parameter
The option noop configures, if the file is being moved or copied. By default it is set to false, which means it is moved
In the to part you configure, where the file is supposed to be moved. Here you can use the fileName parameter to rename the file.
Be careful with this though, because setting an option in the uri directly does make it "static".
What I mean by that is, that the only way of changing the parameter is by completely reconfiguring the route or by restarting it, where neither is something you would want to do normally.
Note 1:
Moving all files that are put into one folder into the same file always overrides the previous file by default.
You could, for example, use the fileExists parameter to always just append the content of the file: fileExists=Append (See camel file docu for details)
Note 2:
There is an option in the file component to not "move" the file, but copy, rename and delete it, which sometimes is necessary, when you want to move it onto a different drive and a simple copy does not work.
Also see the docu for the camel file component for details on that.
Note 3:
You can have multiple to() statements in the same route to have the file moved to multiple locations. For example:
from("file:/home/chris/temp/camel/in")
.to("file:/home/chris/temp/camel/out/?fileName=test.txt")
.to("smtp:....");
Hope I could help you and answer you question.
Greets
Chris
Two possible ways to achieve your goal.
Use both "consumer" and "producer"
Using this way, you are free to control where and how your destination can be set and has great freedom to control filename with the use of a processor/bean.
from("file:D:/inputFolder")
.to("file:D:/outputFolder?fileName=abc.txt")
Use "consumer" only
Using this way, you are treating your work as source data control. This can be use when your file is going to move within same drive. The drawback is the filename rename pattern is limited (refer to camel file language)
from("file:D:/inputFolder?move=${file:parent}/../outputFolder/abc.txt")
Sometimes Typewriter generates output (1).ts files. How can I make it to overwrite the existing files?
Typewriter keeps track of which source file was used to generate the output file in order to automatically update the output file whenever the source file changes. Sometimes this tracking gets out of sync resulting in this behaviour.
To resolve the issue you'll need to delete both output.ts and output (1).ts and then render the .tst template or save the c# source file.
I'm trying to watch for size change on directory using kqueue, is this possible? The reason for this because I am watching directories and whenever an event triggers, I stat the directory and compare last mod times etc to figure out if contents-modifed, added, removed, or renamed events happend. My goal is to get an even to trigger on directory when contents-modified happens on a file inside the directory, I couldn't accomplish that so we had an idea, we want to detect size change on directory, as if a contents-modified happend on a file within then the size of directory will change. Is this possible?
Thanks
You don't want/need to stat() the directory. You need to read the list of files in the directory each time kqueue says the directory was modified, and compare it to the list as it was the last time you read it. Only then will you know if a new file has appeared, or if a file has been removed, or if a file has been renamed (you will also need to keep track of the inode numbers for each file in the list to detect renames).
If you want to further monitor for changes to each file then you also need to add events for each file in the directory and update this list of events each time the event for the directory file is signalled.
FYI: This command-line utility does what you want, and can be built to use kqueue: https://github.com/emcrisostomo/fswatch