let chop_extensions x = let dirname = dirname x and basename = basename x in try let pos = String.index basename '.' in dirname / (String.before basename pos) with Not_found -> invalid_arg "chop_extensions: no extensions"