Java tutorial
//package com.java2s; //License from project: Artistic License import java.io.File; public class Main { public static int getDepth(File file) { if (file.getParent() == null || new File(file.getParent()).getPath().equals(new File(file.getPath()))) return 1; return 1 + getDepth(new File(file.getParent())); } }