| | |
Recursive File List - Help me problem solve please
Thread Solved |
> but i dont think it has had any change in the list of results brought
> to the terminal window
And what were you expecting by checking if the file size is less than or equal to one byte?
Maybe posting/uploading a virtual directory structure along with the expected output might help others in collaborating for a better solution.
> to the terminal window
And what were you expecting by checking if the file size is less than or equal to one byte?
Maybe posting/uploading a virtual directory structure along with the expected output might help others in collaborating for a better solution.
I don't accept change; I don't deserve to live.
I'm fairly sure you meant "files.length" and not "f.length()".
Edit: Not that that matters though. Once the loop is done, the method will return anyway.
Edit: Not that that matters though. Once the loop is done, the method will return anyway.
Last edited by masijade; Jan 12th, 2009 at 2:51 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2008
Posts: 37
Reputation:
Solved Threads: 0
hello again i tried your advice erm no difference I think
I dont quite understand how not to make "the method not return anyway"
Please may someone help me to get files of the same size listed on screen or put into an array (both if possible).
Heres what ive tried so far, (also take a look at the commented out code)
please please help..
I dont quite understand how not to make "the method not return anyway"
Please may someone help me to get files of the same size listed on screen or put into an array (both if possible).
Heres what ive tried so far, (also take a look at the commented out code)
Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; public class scanner { public static void main(String[] args) { for(File file : File.listRoots()){ search(file); // duplicate(file); } } public static void search(File f) { //if (!f.exists()) return; // String name = f.getName(); // System.out.println(name); // if (duplicate(f)) System.out.println(f); if ( f.isDirectory() ) { File[] files = f.listFiles(); //if (files.length == files.length) return; { for( int i = 0 ; i < files.length; i++ ) { if (files[i].length() == files[i].length()) { search( files[i] ); //if (files[i].length() == files[i].length()) return; System.out.println(files[i]); } } } } //public static void duplicate(File file) //{ //if (file.length() == file.length()) return; // } }
please please help..
•
•
Join Date: Nov 2008
Posts: 37
Reputation:
Solved Threads: 0
so just to add more detail because theyre may be confusion
Im basically trying to get files with equal file size first, then im trying to put those in an array, then the files in the array need to be compared possibily by length (bytes) (not file names but files contents), the comparison need to be made maybe by binary contents or by generating an MD checksum which ever ones easier.
Im basically trying to get files with equal file size first, then im trying to put those in an array, then the files in the array need to be compared possibily by length (bytes) (not file names but files contents), the comparison need to be made maybe by binary contents or by generating an MD checksum which ever ones easier.
And I told you that sort of thing would be a lot more work. Good luck with that, we are not going to write it for you.
For arrays:
http://java.sun.com/docs/books/tutor...ts/arrays.html
For Collections (which would be better):
http://java.sun.com/docs/books/tutor...ons/index.html
For arrays:
http://java.sun.com/docs/books/tutor...ts/arrays.html
For Collections (which would be better):
http://java.sun.com/docs/books/tutor...ons/index.html
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
so just to add more detail because theyre may be confusion
Im basically trying to get files with equal file size first, then im trying to put those in an array, then the files in the array need to be compared possibily by length (bytes) (not file names but files contents), the comparison need to be made maybe by binary contents or by generating an MD checksum which ever ones easier.
I don't accept change; I don't deserve to live.
> i just thought you guys would of liked a challenge lol
I have got enough challenges in my daily life, I guess I'll just pass. :-)
But don't give up hope, who knows, masijade might just end up dropping in a jar file here with a "meh" look on his face. ;-)
I have got enough challenges in my daily life, I guess I'll just pass. :-)
But don't give up hope, who knows, masijade might just end up dropping in a jar file here with a "meh" look on his face. ;-)
I don't accept change; I don't deserve to live.
•
•
Join Date: Nov 2008
Posts: 37
Reputation:
Solved Threads: 0
why when i compile this code now i only get a list of folders and .sqm files and .log file and a .txt file and an .exe file. Ive got this list of files from d and c drive
Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; import java.*; import java.io.*; import java.util.*; public class DeleteSameFilesAttempt9x10 { public static void main(String[] args) { for(File file : File.listRoots()){ search(file); } } public static void search(File f) { if ( !f.exists() ) return; String name = f.getName(); System.out.println(name); if ( f.isDirectory() ) { File[] files = f.listFiles(); if (files != null) { for( int i = 0 ; i < files.length; i++ ) { samesize( files[i], files[i] ); { System.out.println(files[i]); } } } } } public static void samesize (File filey, File filex) { if (filey != null) if (filex !=null) { if (filey.length() == filex.length()) return; String name1 = filey.getName(); String name2 = filex.getName(); System.out.println(name1 + name2); } } }
![]() |
Similar Threads
- Solving Towers of Hanoi (C++)
- MIPS Recursive Programming, Help please! (Assembly)
Other Threads in the Java Forum
- Previous Thread: Requiring programs in java
- Next Thread: very basic sun tutorial base question
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal free game gis givemetehcodez graphics gui guidancer html ide image inetaddress integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






