• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Hard Drive Search

Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing a project which performs a search on the C drive of a machine. I would like to display the name of the file currently being searched. Anybody know how I could do this?? I presume that I will need some sort of listener to get the name to change as the file being searched changes, I'm not sure how to do this though.

Thanks in advance!
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

This is relatively simple, but first of all, do your long running task in a separate thread to the swing ui thread otherwise you have a very unresponsive and broken ui.

So, assuming you have a nice worker thread and an algorithm for traversing your disk, a simple one being (in pseudo code)

SearchFile(target directory):

1) from target director

2) for each file in target directory
3) search file

4) for each folder in target directory
5) SearchFile(selected child folder)

This is obviously a depth first recursive search and if you have an extremely deep directory structure you may run out of stack space - but it will do.

What this illustrates though is that you have a handle onto the file that is being searched in step 3). So quite simply, from that step, use what ever notification method you desire to notify some ui component/form that a file is being searched. This could be either having a "filesearched" custom event (better) or a handle onto the component/form and update some text (worse as its tightly coupled).

Remember though that if you update a component from a worker thread (and not the swing ui thread) then you will need to marshal the call across onto the swing ui thread with invokeLater. Do a search on Google for SwingWorkerThread and you'll find out more.
[ April 05, 2005: Message edited by: Jason Kingsley ]
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic