java 搜索目录时控制搜索深度,递归实现

private void extractAll(String dirpath, int currentDeepth)
	{
		int deepth = currentDeepth;
		System.err.println("deepth = " + deepth);
		if(deepth > config.searchDeepth)
		{
			System.out.println("deepth > config.searchDeepth , return ");
			return;	
		}
			
		
		File dir = new File(dirpath);
		File[] files = dir.listFiles();
		
		for(int i= 0; i < files.length;i++)
		{ 
			if(files[i].isDirectory())
			{
				System.err.println(files[i].getAbsolutePath());
				
				if(files[i].getName().equals("res"))
				{
					//ExcelWriter excelWriter = new ExcelWriter();
					//excelWriter.write(new XMLReader().read(dirpath));
					System.out.println("read res dir");
				//	return ;
				}
				
				extractAll(files[i].getAbsolutePath(), deepth + 1);
			}
		}
	}

你可能感兴趣的:(java,递归,深度,目录搜索)