This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

file searching with file name in a specific root directory  RSS feed

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 61718
193
  • Mark post as helpful
  • send pies
  • 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
  • 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]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!