• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

searching a file in hierarchy and delete

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i have to delete a file from a directory structure .i donot know where is file stored in my folder hierarchy .i have to search that file and delete that file .

for example ;
i have a folder name A , which have folder B ,C ,D ,E . B folder have other 2 folder or 3 file (anything) , same C and D And E can have file or folder . means we donot know that A folder have how many files or folder in it . in that we have to search a specific file and delete it .


 
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
All that is necessary to do this (listing files and subdirectories in a directory and deleting a file) is in the API of the class java.io.File. So lookup the documentation for that class.
 
Jesper de Jong
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
Karan replied to me in a private message, which I'm inluding below:

Note: Karan, please use the forums instead of private messages. If you use the forums, everybody can read your message and help you.

Karan wrote:


hi ,

thanks for your suggestion . i read all API .

but i was expecting more then that .

i made one code , this is working for one level only(1 depth).can you please make it recursive or make it for search for more level .



hope you are sending solutions .


What did you try yourself to make it recursive? Do you understand how to write a recursive method? If not, search around on Internet or in books about how to write a recursive method.

The basic idea what a recursive method should do is this:

- List all the files and directories in the given directory (the directory should be supplied as a method argument).
- Loop through all the files and directories in the list. For each file or directory:
- Is it a directory? If yes, then call the method itself (recursion) with that directory as the argument.
- Is it the file we are looking for to delete? If yes, then delete the file.
 
My pie came with a little toothpic holding up this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic