aspose file tools*
The moose likes Beginning Java and the fly likes delete files in a driectory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "delete files in a driectory" Watch "delete files in a driectory" New topic
Author

delete files in a driectory

Kiran Gaddam
Ranch Hand

Joined: Aug 05, 2011
Posts: 32
Hello All,

I need to write code to delete all the files in a specified directory, but not the directory..

I have this code...



but it is deleting the whole folder and files in it ( "C:/Users/aaaa/Desktop/asdf").
I only want the files in the folder to be deleted... not the folder

any ideas is appreciated..

Thankyou
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, yes, that's what line 22 does. So apparently you want the starting directory (your "specified" directory) to be treated differently than the directories under it. The starting directory should be left alone but the directories under it should be deleted.

Everything else in your code looks just fine: recursive method (good), don't delete directory until everything in it has been deleted (good), but unfortunately you treat the starting directory the same as the others (not good). So you're going to need additional code which takes care of that particular situation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: delete files in a driectory