you can use the total number of backslashes in a string that will give you the same answer. Like this
StringTokenizer stOR = new StringTokenizer ("C: \ foo \ bar \ otherfolder \ subfolder", "\");
Windows, . escape- (:\b\t\n\f\r\"\ '\)
int orCount = stOR.countTokens() - 1;
System.out.println(orCount);