?
Solved

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

Posted on 2009-05-07
7
Medium Priority
?
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

770 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