This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

delete files in a driectory

 
Kiran Gaddam
Ranch Hand
Posts: 35
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20201
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic