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 .
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.
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.