• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file searching with file name in a specific root directory

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a file name as "FileToBeRetrieved.txt", which might be located under any folder under one root folder. I know only the root folder while my run-time, and I can't surely say the needed file is in under specific path. Please see the attached image for better understanding. In that I've marked the required file with blue color.

So From the specific root folder, is there any possibility to search and retrieve that specific file.. ?

Filename: filesearch.bmp
File size: 610 Kbytes
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class java.io.File contains methods for listing the files and subdirectories that are present in a directory. To find a file that is somewhere down in a subdirectory, you'd have to call these methods recursively on the subdirectories, until you find the file that you're looking for. Have a look at the API documentation of class java.io.File.
 
Bharath Raja
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Class java.io.File contains methods for listing the files and subdirectories that are present in a directory. To find a file that is somewhere down in a subdirectory, you'd have to call these methods recursively on the subdirectories, until you find the file that you're looking for. Have a look at the API documentation of class java.io.File.



Thanks Jesper.. Actually I've started this approach already, but may I know, is this the only way to achieve this..? Can't we have any api say directly search the file in single method ... and FYI I'm working this scenario in eclipse (root directory is my workspace, that can we retrieve through eclipse core api)

do you know any api for done this in eclipse, please let me know...
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse is not a runtime, but a development environment. It uses the standard Java™ API, and any other API you need to download and add to your classpath. When you have finished developing, it should work by [double-]clicking the resultant .jar. Use the same API you would use without Eclipse.
 
Bharath Raja
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Eclipse is not a runtime, but a development environment. It uses the standard Java™ API, and any other API you need to download and add to your classpath. When you have finished developing, it should work by [double-]clicking the resultant .jar. Use the same API you would use without Eclipse.



Ritchie., I'm in mid of developing plug-in which fits into eclipse. The actual requirement is, have to get a file as IDocument with just file name not full path of the file. As I mentioned in attachment, we can get the current user workspace through code, under that workspace there could be many projects(or folders), and files. Within that user current workspace I need to retrieve the file with its name. Since we can't surely say the file lying under specific folder, we cant give the full path ... isn't it.? As of now I've implement logic said by jesper and able to get the file,. But my question is, don't we have any other option to do this ..?

[For more explanation of requirement, how the "open resources" functionality working in eclipse. In that "open resources" if we type any name of the file without bothering about where its lying (must be in current workspace), the eclipse have intelligence to open that file right... same thing is I want to achieve in my plug-in]
 
I knew that guy would be trouble! Thanks tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic