Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop not counting

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
So I found the getImageCount function in another forum on the internet (don't remember which one)...but anyway, it's not working the way I'd like. It's looping through the folder but never incrementing count correctly (the getPath() shows each file in the folder)...but count stays at 0...I've tried having count as a class variable and an instance variable, but it doesn't ever increment...can someone explain why this isn't working correctly?

Thanks!

Code:
import java.io.*;

public class ScannedImageFolder {
	
    private File currentFolder;
    private int imageCount;
    private boolean timeToChange = false;
    int count = 0;

    ScannedImageFolder(String c){
        currentFolder = new File(c);
        imageCount = getImageCount(currentFolder);
        settimeToChange();
    }
    
    public int getImageCount(){
    	return imageCount;
    }
    
    public File getCurrentFolder (){
        return currentFolder;
    }
    
    public void setCurrentFolder(String c){
        currentFolder = new File(c);
    }
    
    [b]private int getImageCount(File file) {
    	 System.out.println("file getPath = " + file.getPath()); //shows correct file names
        
    	
    	
        File[] files = file.listFiles();
        if (files != null)
        {
            for (File f: files)
            {
                count += getImageCount(f);
            }
        }
        System.out.println("current count = " + count);
        return count;
        
    }[/b]
    
    private void settimeToChange () {
        if (imageCount > 12000){
            timeToChange = true;
        }
    }
}


public class ScannedImageFolderTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ScannedImageFolder test = new ScannedImageFolder("\\\\srvname\\imaging\\Citationimages\\00000036\\");
		System.out.println("current folder:" + test.getCurrentFolder());
		System.out.println("image count:" + test.getImageCount());

	}

}

Leslie

Have you met Hardy Heron?
 
I figured it out! I did this instead:
Code:
import java.io.*;

public class ScannedImageFolder {
	int count = 0;
	private File currentFolder;
    private int imageCount;
    private boolean timeToChange = false;
    
    ScannedImageFolder(String c){
        currentFolder = new File(c);
        imageCount = getImageCount(currentFolder);
        settimeToChange();
    }
    
    public int getImageCount(){
    	return imageCount;
    }
    
    public File getCurrentFolder (){
        return currentFolder;
    }
    
    public void setCurrentFolder(String c){
        currentFolder = new File(c);
    }
    
[b]    private int getImageCount(File file) {
    	 System.out.println("file getPath = " + file.getPath()); //shows correct file names
        
    	
    	
        File[] files = file.listFiles();
        if (files != null)
        {
            for (File f: files)
            {
                count ++;
            }
        }
        System.out.println("current count = " + count);
        return count;
        
    }[/b]
    
    private void settimeToChange () {
        if (imageCount > 12000){
            timeToChange = true;
        }
    }
}
 
Nice to know it works.

Btw, I'd use the Java forum for this kind of questions. This forum is intended for J2EE questions.

Cheers,
Dian
 
lespaul, You should try little more and think little more before you ask a question. You have the ability to spot the problem.
You may have more progress in solving the problem in using Java.
It is the second time that you solve your problem by yourself.
Congratulations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top