Results 1 to 4 of 4
- 11-16-2008, 02:36 PM #1
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
[SOLVED] To Delete All subdir in a directory
import java.io.File;
class DeleteDir {
public static void main(String args[]) {
deleteDirectory(new File(args[0]));
}
static public boolean deleteDirectory(File path) {
if( path.exists() ) {
File[] files = path.listFiles();
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
return( path.delete() );
}
}
Could anyone tell me that where I should write the dir name which I want to del?A stitch in time saves nine:D
- 11-16-2008, 04:07 PM #2
no need to keep name
Well, you could do this:
but why do we need the file name?Java Code:class DeleteDir { // name of ?..... String fileToDelete; DeleteDir(String fileToDelete){ fileToDelete = fileToDelete; } public static void main(String args[]) { File aFile = new File(args[0]); DeleteDir dd = new DeleteDir(args[0]); deleteDirectory(aFile)); } }
Looks very similar to recursive directory search, or is something similar.
I am working on recursive directory search this morning, if file is to be deleted - why do we need the name?
(errors in code while getting clarifications)Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-16-2008, 09:59 PM #3
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
Dear Nicholas,
Thank you for quick reply. I try to make a telephone directory. I wrote some programme code which allows user to add new people. When you add a new person, program creates a folder and some txt files into that folder. Now I just want my program to delete a person's folder and all its sub directories which will be entered by user. Thats what I am trying to do.
Thanks for help:)
Kind Regards,
Salih Ozan IRBIKA stitch in time saves nine:D
- 11-18-2008, 12:29 PM #4
Try Web4J
I have looked around and this coder knows good practices and so on. I copied a recursive directory search, but noticed it had a copyright attached so suggest just dig around Hirondelle's site - some work involved but is just what you need.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
How to delete the records
By kiran kumar in forum Java ServletReplies: 6Last Post: 11-09-2008, 01:16 PM -
Delete
By Sarinam in forum New To JavaReplies: 6Last Post: 07-23-2008, 11:09 AM -
Listbox Add/Delete
By Rageagainst20 in forum New To JavaReplies: 2Last Post: 04-16-2008, 04:49 PM -
How to make delete particular extension file from a directory
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:13 AM -
How to delete a file
By Alpha in forum New To JavaReplies: 1Last Post: 05-26-2007, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks