Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:36:23+00:00 2026-06-15T23:36:23+00:00

Introduction I need to create an iterator over a filesystem subtree (e.g. an iterator

  • 0

Introduction

I need to create an iterator over a filesystem subtree (e.g. an iterator that would, given a folder, return all files contained inside, in a depth-first-search order, one at every next method call).

The contents of the subtree can change over time, e.g. it is possible (and probable) that, while the iteration is still in progress, new subfolders and files will get created and some of the existing ones will get deleted.

Fortunatelly the following conditions are acceptable:

  • the implementation can (but it would be better if it did not) skip newly created files (e.g. files that originated after the iteration started) and folders (and files in those folders), or even just some of them,

  • the implementation can (but it would be better if it did not) list deleted files (e.g. files that no longer exist but were present when the iteration started), or even just some of them.


Motivation

In order to give you a better insight into the rationals behind those decisions, I’d like to briefly describe the application as a whole.

It is a producer/consumer -like application. A web service (the producer) would accept files and store them on a local filesystem, somewhere in the subtree hierarchy.

Another application (the consumer) would process these files. It would be invoked periodically via CRON every few minutes. When launched, it would crawl the subtree, find all documents, and hand them over to be processed (to yet another application, if that’s relevant). After a document is processed, it gets deleted from the local filesystem.

The problem is that the producer and the consumer would be running at the same time. Moreover, multiple instances of the consumer application might be running at the same time as well. E.g. while a consumer is crawling the subtree, new documents might get created and existing documents might get deleted. Even the structure of subdirectories might get modified.

Because the crawler gets launched periodically every few minutes, it does not matter if it consumes all the documents available at the time (especially those produced while the consumer is running). It is only important that a produced document gets eventually consumed (with a reasonably small delay). That’s where the relaxing conditions listed above come from.


Possible solutions

I first thought I would create a snapshot of the subtree into memory at launch time (e.g. the list of documents to be processed) and then iterate over them. See my other post. But the hierarchy might be very large (even tens of thousands of documents processed per a few hours) and I was thinking that this approach might have unacceptable performace demands (memory & speed).


How would you implement such an iterator?


Thanks very much for your help and sorry for the big length of the post.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:36:23+00:00Added an answer on June 15, 2026 at 11:36 pm

    Since you cannot use JDK 7 directly you may still look at how they did it there : FileTreeWalker

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the verbose introduction that follows. I need insight from someone knowing P/Invoke
I have a boatload of text files (see below) that I need to parse.
I am new to android. I would like to create a database that will
Introduction Google chrome has a feature that allows you to create shortcuts to web
I need to read A Practical Introduction to Data Structures and Algorithm Analysis by
Alright... my Introduction to Data Structures from CS is so rusty I need to
Introduction I have been so annoyed by applications that have a startup dialog which
Introduction: Now I know this question could be very broad and it would be
Introduction: I want to loop through XML files with flexible categories structure. Problem: I
I need to create a figure window with two plots at the same time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.