473,474 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Watching a File for Changes

I would like to, cleanly, watch a flat file for changes (updates and
the like). The file will be altered by another program... I found some
example code (which actually didn't compile) on Google, but it
essentially does it the way I would have in the first place (i.e. sets
up a loop and gets the file's attributes each iteration, comparing to
the previous instance). This seems kind of cludgy to me: is there a
better way?

Thank you :)
Christopher Harrison

Nov 15 '05 #1
8 2196
"Christopher Harrison" <Sp*********@ChrisHarrison.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I would like to, cleanly, watch a flat file for changes (updates and
the like). [...]


Then you should look into platform-specific methods, and if necessary ask in
the relevant group(s).

The closest you can get using standard C, the scope of this newsgroup, is to
make a copy of the file (either read it into memory or read it and write to
another file) and repeatedly compare the file with the copy. That certainly
isn't what I'd call "clean" :).

Alex
Nov 15 '05 #2
Alex Fraser wrote:
"Christopher Harrison" <Sp*********@ChrisHarrison.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I would like to, cleanly, watch a flat file for changes (updates and
the like). [...]


Then you should look into platform-specific methods, and if necessary ask in
the relevant group(s).

The closest you can get using standard C, the scope of this newsgroup, is to
make a copy of the file (either read it into memory or read it and write to
another file) and repeatedly compare the file with the copy. That certainly
isn't what I'd call "clean" :).


You could also compute a CRC or a hash from the file, store it in
memory and compare in each iteration with the stored value. But this is
not much cleaner than simply copying the file and compare directly, and
eats much more processor time.

Nov 15 '05 #3
I've been looking around and have found sys/stat.h which I'm currently
working with... I know I'm asking for trouble, but could someone
explain to me why this isn't "standard C". I read it's POSIX (although
it seems to be working OK under) Windows: what's the difference?

Nov 15 '05 #4
Christopher Harrison wrote:
I've been looking around and have found sys/stat.h which I'm currently
working with... I know I'm asking for trouble, but could someone
explain to me why this isn't "standard C".
It isn't defined by the C Standard (not any of them). By default,
the comp.lang.c interpretation of "the standard" is the appropriate
C standard.

Consequently, a C implementation is under no obligation to provide
a sys/stat.h, nor - if it does - for any functions inside to do
what you expect, /as far as the C standard is concerned/. Your
implementation may of course offer items taken from some /other/
standard ...
I read it's POSIX (although
it seems to be working OK under) Windows: what's the difference?


.... such as POSIX; the difference is that, generally speaking,
what POSIX offers isn't topical here.

--
Chris "electric hedgehog" Dollin
Il Principe - Byzantium - Hansa - Antike - King's Progress
Farfalia - Mu - Havoc - Tigris & Euphrates [kartenspiel]
Nov 15 '05 #5
Christopher Harrison <Sp*********@chrisharrison.co.uk> wrote:
I've been looking around and have found sys/stat.h which I'm currently
working with... I know I'm asking for trouble, but could someone
explain to me why this isn't "standard C". I read it's POSIX (although
it seems to be working OK under) Windows: what's the difference?


http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

Also...

It is proper Usenet etiquette to include the relevant portions of the text
you are replying to. To do this using Google groups, please follow the
instructions below, penned by Keith Thompson:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #6
Christopher Harrison <Sp*********@chrisharrison.co.uk> wrote:
I would like to, cleanly, watch a flat file for changes (updates and
the like). The file will be altered by another program... I found some
example code (which actually didn't compile) on Google, but it
essentially does it the way I would have in the first place (i.e. sets
up a loop and gets the file's attributes each iteration, comparing to
the previous instance). This seems kind of cludgy to me: is there a
better way?


Judging from this thread you should take this to comp.unix.programmer.

There you can learn about things like dnotify, inotify, kqueue(2), and other
techniques (similar to sleep and stat). None of them can be done in what
plain C offers. They all require platform specific support (API's), and by
asking in the wrong group you're likely to get confusing or misleading
answers (either because the people are too experienced in a domain or not
enough, and the group isn't tuned for correcting and normalizing nontopical
subjects).
Nov 15 '05 #7
On Tue, 18 Oct 2005 19:13:52 +0000, Christopher Benson-Manica wrote:
Christopher Harrison <Sp*********@chrisharrison.co.uk> wrote:
I've been looking around and have found sys/stat.h which I'm currently
working with... I know I'm asking for trouble, but could someone
explain to me why this isn't "standard C". I read it's POSIX (although
it seems to be working OK under) Windows: what's the difference?


http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html


More directly:

POSIX (and the related term SUS) is an operating system standard for
UNIX-like operating systems. It extends the C standard but also applies
to more than just C. The searchable contents of the current standard
are here:
http://www.opengroup.org/onlinepubs/...9/nfindex.html

This newsgroup does not deal with those extensions, it deals only with the
(quite limited) C standard itself. The current version of the standard is
C99; the more popularly implemented earlier version is C90 aka C89. You
can view free drafts of both (but must pay for a - only slightly variant -
final version) at:

http://dev.unicals.com/papers/c89-draft.html
http://dev.unicals.com/papers/c99-draft.html

If you are unsure whether something is POSIX-only or an extension of the C
standard, search those three sources.

Windows attempts to implement as much of POSIX as it can and apparently
stat.h is one of those areas.

[...]
--
http://members.dodo.com.au/~netocrat
Nov 15 '05 #8
On 18 Oct 2005 05:52:47 -0700, in comp.lang.c , "Christopher Harrison"
<Sp*********@ChrisHarrison.co.uk> wrote:
I've been looking around and have found sys/stat.h which I'm currently
working with... I know I'm asking for trouble, but could someone
explain to me why this isn't "standard C".
C supports hardware and OSes for which the functions in stat.h would
be either unimplementable or meaningless. Even for those for which a
posix layer exists, some of the functionality doesn't always make
sense, for example dev, ino, mtime, atime, nlink, gid, uid, in struct
_stat under DOS or Win9x.
I read it's POSIX (although
it seems to be working OK under) Windows: what's the difference?


POSIX is defined by one Standard, ISO C is defined by another.

FWIW posix provides a set of unix-like APIs which work on a range of
hardware that C cupports, but far from all of it.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Benjamin D. LeMasurier | last post by:
Hey everyone, Is there a way to "watch" a file for changes? I know I could poll the file every few seconds and check to see if the buffer has changed but is there a cleaner way? thanks! Ben
6
by: Ajay Pal Singh | last post by:
Hi, I am creating a web service, which needs to take some actions based on the config file. I need a way to listen the changes as they occur in the config file so that the service can take...
3
by: Luis Esteban Valencia Muñoz | last post by:
Hi everyone, I created a VB.NET application that looks at a folder in my local system from which I can read the file, enter data into the database and delete the file. I am using the filewatcher...
2
by: paul | last post by:
Watching connections to your computer. Can some one tell where to start. I want to write some code to be alerted when some one connect to my computer and browses/copies/changes files or...
4
by: John Dann | last post by:
I need to watch a specific file that updates at irregular intervals and raise an event when an update happens (ie file date/time stamp changes). I had heard that there is a native method in .Net...
0
by: John Dann | last post by:
I'm using the FileSystemWatcher with NotifyFilters.LastWrite set. This works fine during the same day but fails to fire its event for changes in the monitored file after midnight, ie into the next...
8
by: Gordon Airporte | last post by:
I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the...
14
by: Zed A. Shaw | last post by:
Hi Everyone, Just putting out an announcement that I've released a new version of Vellum numbered 0.16. This version should be ready for people to use as not much of the internal structure has...
5
by: Andrew Cooper | last post by:
I've got an application that I'm modifying and the client needs it to watch a particular file and then do some stuff when that file gets modified. For example, let's say the file is C:\Test.dat...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.