Solved

Monitor files in a specific directory in C Programming Language in UNIX

Posted on 2009-05-07
7
515 Views
Last Modified: 2013-12-26
Hi,

Is there a way we can monitor files in a specific directory in UNIX using C Programming Language?

What I want is, when a file (file1.txt) in a directory (example A directory) is moved to different directory (B directory) my C program will log it in a file. The program will add a line on a log file like:
"file1.txt is moved to B directory" ...

Is this possible in C? How? Or do you have any other recommendations?

Thanks a lot.

-jan
0
Comment
Question by:janjerell
  • 3
  • 3
7 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 24333646
Take a look at the inotify API

http://ibm5.ma.utexas.edu/cgi-bin/man-cgi?inotify+7

"The inotify API provides a mechanism for monitoring file system events.
Inotify can be used to monitor individual files, or to monitor directo-
ries.   When  a  directory is monitored, inotify will return events for
the directory itself, and for files inside the directory."

NB. The inotify API replaces the older dnotify.
0
 
LVL 3

Author Comment

by:janjerell
ID: 24334150
Thanks so much evilrix... I'll get back to you soon as I figured this out...
0
 
LVL 3

Author Comment

by:janjerell
ID: 24362431
Thanks evilrix.. I have it working right now... SOrry for the Grade.. It should be A.. I don't know how to change.. anyway, thanks again...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Expert Comment

by:evilrix
ID: 24362449
>> Thanks evilrix..
Most welcome.

>> SOrry for the Grade.. It should be A.
If you'd like to change the grade you can "Request Attention" by clicking the link at the top right of the page and posting a request in Community Support.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24371947
Many thanks indeed.
0
 
LVL 3

Author Comment

by:janjerell
ID: 24372036
thanks mod
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
if loop in java 3 128
pre4 challenge 19 93
JQuery serialize and unserialize 8 48
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now