• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to delete folder when deleting file inside it  RSS feed

 
biraj joshi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can we delete the folder too when deleting the file inside it using Runtime.exec() function.I have the file name buy not the folder name.So when my code deletes that file inside the folder i want the folder to be deleted as well,as its empty.

Thanks in advance
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Runtime.exec to delete a file and folder ?
The File and Files classes have methods for doing exactly that and will keep your code OS independent.
There are also methods for getting the name of the parent directory of a file or directory.
 
biraj joshi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know the folder name. how to get foldername from its file name
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
biraj joshi wrote:I dont know the folder name. how to get foldername from its file name

Did you look at the javadoc for the File and Files classes ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!