Solved

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

Posted on 2009-05-07
7
520 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

726 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