[jcifs] smbFile.list/listFiles - 'max' type setting?

Michael B Allen ioplex at gmail.com
Fri Nov 25 23:57:44 MST 2011


On Tue, Nov 22, 2011 at 10:40 AM, Darren Hartford
<binarymonk01 at yahoo.com> wrote:
> Hey all,
> I'm using the great features of jcifs, and the smbFile.list() and smbFile.listFiles(), both with filters.
>
>
> However, I only want to work on a portion of files at a time, but it appears (even with the filters set) it spends a lot of time spinning through all the files in a directory instead of only the (first) X amount I want to look at.
>
> My process I move files out of the directory after review, so I know they will be moved out so I can look at the next 'X' amount.
>
> Question: Is there a way to limit/stop looking for files after a set number that prevents further processing?  The filters themselves still review each file, while I would rather under-the-covers just stop checking all together after a set number.
>

Well you could just throw an SmbException from your filter accept
method. It's a little crude only in that a proper SmbComFindClose2
command will not be sent. But CIFS reads directory entries in chunks
so it will stop the listing. Of course you will not get the SmbFile[]
list returned so you will have to either do your business in accept()
or make your own list.

> Usecase: a directory with 100k files, looking at 10 files at a time (either through smbFile.list or smbFile.listFile, latter is my primary usage), but still spins through all 100k files per 10 file review.

Note that if you return false from your SmbFileFilter accept method
JCIFS will not construct an SmbFile object for that entry and thus it
should be quite efficient. Look at examples/LargeListFiles.java. It
should only take a second or two to go though 100K directory entries.
If the server cache is hot I would think it should only take a few
milliseconds actually.

It's a fairly unusual use-case to want to quit in the middle of a dir
listing. Maybe if you're searching for one file that meets some
criteria. But again it should be very fast to read the directory
entries because even hundreds of thousands of files equates to reading
a few megabytes of data.

Mike

-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


More information about the jCIFS mailing list