FileNameDepth

FileNameDepth["name"]
gives the number of path parts in the given filename.