Thread View: borland.public.jbuilder.java.api
5 messages
5 total messages
Started by gary
Wed, 31 Dec 2003 03:53
monitoring directory tree changes
Author: gary
Date: Wed, 31 Dec 2003 03:53
Date: Wed, 31 Dec 2003 03:53
9 lines
1432 bytes
1432 bytes
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?
Re: monitoring directory tree changes
Author: Shankar Unni
Date: Wed, 31 Dec 2003 22:23
Date: Wed, 31 Dec 2003 22:23
15 lines
1698 bytes
1698 bytes
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..
Re: monitoring directory tree changes
Author: gary
Date: Thu, 01 Jan 2004 03:08
Date: Thu, 01 Jan 2004 03:08
37 lines
2583 bytes
2583 bytes
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: > 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..
Re: monitoring directory tree changes
Author: John McGrath [TeamB]
Date: Fri, 02 Jan 2004 05:29
Date: Fri, 02 Jan 2004 05:29
21 lines
1796 bytes
1796 bytes
On 12/31/2003 at 10:08:49 PM, gary wrote:
> 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
Re: monitoring directory tree changes
Author: Shankar Unni
Date: Fri, 02 Jan 2004 20:40
Date: Fri, 02 Jan 2004 20:40
18 lines
1869 bytes
1869 bytes
gary wrote:
> 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads