 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
gary Guest
|
Posted: Wed Dec 31, 2003 3:53 am Post subject: monitoring directory tree changes |
|
|
hello. let me first say that if i've chosen the wrong newsgroup for
this question, please advise me as to a better choice. thanks.
now, i'm wondering if there is a java API equivalent to the Visual C++
"FindFirstChangeNotification() / FindNextChangeNotification()", which
allows you to write a simple thread that essentially camps out on a
given (single) directory or sub-directory tree looking for changes like:
file rename, attribute changes, creation, deletion, etc., and allows the
waiting thread to respond to such changes?
|
|
| Back to top |
|
 |
Shankar Unni Guest
|
Posted: Wed Dec 31, 2003 10:23 pm Post subject: Re: monitoring directory tree changes |
|
|
gary wrote:
| Quote: | now, i'm wondering if there is a java API equivalent to the Visual C++
"FindFirstChangeNotification() / FindNextChangeNotification()",
|
This is not a "Visual C++", or even a "C++" feature - it's a Windows OS
feature. And no, there's nothing like that in Java.
Java generally doesn't include features that are found only in a single
OS, and are extremely specific to that OS implementation (like the
Windows ChangeNotification APIs, etc.).
If you really need to use extremely Windows-specific features, write a
JNI wrapper, and call that. Your program will then only run on Windows,
but that's apparently what you want, so that's OK..
|
|
| Back to top |
|
 |
gary Guest
|
Posted: Thu Jan 01, 2004 3:08 am Post subject: Re: monitoring directory tree changes |
|
|
shankar:
thanks. you are right, of course, about the Windows API. i let myself
get a bit too terse in my question, which was about performing a task in
Java that i used to perform in C++ via the mentioned Windows API calls.
This got contracted into a mention of non-existent "C++" calls.
i guess your comment about the JNI wrapper is the "right" answer to my
somewhat screwed up question. the utility i need is one that would only
run on windows, because it is meant to support a 3rd-party program that
only runs under windows. even so, i'd rather do it in a way that was
more generic. in C, i'd probably just traverse directories doing stat()
calls and looking at timestamps, but i don't know java enough to know
its file system features yet, so i'll have to look into a rough
equivalent to this C library call.
thanks for your reply.
Shankar Unni wrote:
| Quote: | gary wrote:
now, i'm wondering if there is a java API equivalent to the Visual C++
"FindFirstChangeNotification() / FindNextChangeNotification()",
This is not a "Visual C++", or even a "C++" feature - it's a Windows OS
feature. And no, there's nothing like that in Java.
Java generally doesn't include features that are found only in a single
OS, and are extremely specific to that OS implementation (like the
Windows ChangeNotification APIs, etc.).
If you really need to use extremely Windows-specific features, write a
JNI wrapper, and call that. Your program will then only run on Windows,
but that's apparently what you want, so that's OK..
|
|
|
| Back to top |
|
 |
John McGrath [TeamB] Guest
|
Posted: Fri Jan 02, 2004 5:29 am Post subject: Re: monitoring directory tree changes |
|
|
On 12/31/2003 at 10:08:49 PM, gary wrote:
| Quote: | even so, i'd rather do it in a way that was more generic. in C, i'd
probably just traverse directories doing stat() calls and looking at
timestamps, but i don't know java enough to know its file system
features yet, so i'll have to look into a rough equivalent to this C
library call.
|
See the java.io.File class. You can list the contents of a directory
with the list() or listFiles() methods on a File object that refers to
a directory. You can get attributes of a file using methods such as
lastModified(), canRead(), canWrite(), and length().
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
|
|
| Back to top |
|
 |
Shankar Unni Guest
|
Posted: Fri Jan 02, 2004 8:40 pm Post subject: Re: monitoring directory tree changes |
|
|
gary wrote:
| Quote: | in C, i'd probably just traverse directories doing stat()
calls and looking at timestamps,
|
Oh, hey, if you're willing to do that, there's a portable way to do it:
use the java.io.File class.
File has a lot of "stat"-like information, and you can use
File.listFiles() to list all the Files under a File which corresponds to
a directory (e.g. new File("c:\temp").listFiles()). Just walk the
array, and look at the lastModified() time. Be prepared to test
isDirectory() and recursively walk any subdirectories.
This is definitely not efficient, either time or memory wise (the
listFiles() will do a full ls -d inside the directory and return you one
giant list, so if you have 100000 files in that directory, watch out).
But it's quite portable.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|