Recursive File List - Help me problem solve please

Thread Solved

Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Recursive File List - Help me problem solve please

 
0
  #11
Jan 12th, 2009
> 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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,327
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Recursive File List - Help me problem solve please

 
0
  #12
Jan 12th, 2009
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.
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: Recursive File List - Help me problem solve please

 
0
  #13
Jan 13th, 2009
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)

  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class scanner {
  5.  
  6. public static void main(String[] args) {
  7. for(File file : File.listRoots()){
  8. search(file);
  9. // duplicate(file);
  10. }
  11. }
  12.  
  13. public static void search(File f)
  14. {
  15. //if (!f.exists()) return;
  16. // String name = f.getName();
  17. // System.out.println(name);
  18. // if (duplicate(f)) System.out.println(f);
  19. if ( f.isDirectory() ) {
  20. File[] files = f.listFiles();
  21. //if (files.length == files.length) return; {
  22. for( int i = 0 ; i < files.length; i++ ) {
  23. if (files[i].length() == files[i].length()) {
  24. search( files[i] );
  25. //if (files[i].length() == files[i].length()) return;
  26. System.out.println(files[i]);
  27. } } } }
  28.  
  29.  
  30.  
  31. //public static void duplicate(File file)
  32. //{
  33.  
  34. //if (file.length() == file.length()) return;
  35. // }
  36. }

please please help..
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: Recursive File List - Help me problem solve please

 
0
  #14
Jan 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,327
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Recursive File List - Help me problem solve please

 
1
  #15
Jan 14th, 2009
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
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Recursive File List - Help me problem solve please

 
0
  #16
Jan 14th, 2009
Originally Posted by caps_lock View Post
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.
Like it has already been mentioned by masijade, you have to make a stab at this and post again if you have any problems. Just putting in random conditional statements here and there won't cut in. Since you already seem to know the logic, you can at least try implementing it.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: Recursive File List - Help me problem solve please

 
0
  #17
Jan 14th, 2009
i just thought you guys would of liked a challenge lol

thanks anyways
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Recursive File List - Help me problem solve please

 
1
  #18
Jan 14th, 2009
> 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 don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: Recursive File List - Help me problem solve please

 
0
  #19
Jan 14th, 2009
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

  1. import java.io.*;
  2. import java.util.*;
  3. import java.*;
  4.  
  5. import java.io.*;
  6. import java.util.*;
  7.  
  8. public class DeleteSameFilesAttempt9x10 {
  9. public static void main(String[] args) {
  10. for(File file : File.listRoots()){
  11. search(file);
  12. }
  13. }
  14.  
  15.  
  16.  
  17. public static void search(File f) {
  18. if ( !f.exists() ) return;
  19. String name = f.getName();
  20. System.out.println(name);
  21. if ( f.isDirectory() ) {
  22. File[] files = f.listFiles();
  23. if (files != null) {
  24. for( int i = 0 ; i < files.length; i++ ) {
  25. samesize( files[i], files[i] ); {
  26.  
  27. System.out.println(files[i]);
  28.  
  29. }
  30.  
  31.  
  32.  
  33. }
  34. }
  35.  
  36. }
  37. }
  38.  
  39. public static void samesize (File filey, File filex) {
  40. if (filey != null) if (filex !=null)
  41. {
  42. if (filey.length() == filex.length()) return;
  43. String name1 = filey.getName();
  44. String name2 = filex.getName();
  45. System.out.println(name1 + name2);
  46. }
  47. }
  48. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Recursive File List - Help me problem solve please

 
0
  #20
Jan 14th, 2009
I don't even understand what you mean by that question. Your code is only processing the top level of each root entry and only then if it's a directory.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC