Get file path without filename

I am fetching some images with javascript from a route call, and I need to set the correct srcset attribute:

return `
 <img class="image"
  `srcset="${item.image_path}${item.image_name}-600x.jpg 600w
           ${item.image_path}${item.image_name}-1200x.jpg 1200w
           ${item.image_path}${item.image_name}-1600x.jpg 1600w"
  sizes="(max-width: 500px) 100vw, (max-width: 1200px) 40vw, (max-width: 2200px) 30vw, 25vw"
  src="${item.image}"
  alt="${item.alt}">
`

$file->url() returns the whole url, but I need to interpolate the size part in it.
How can I get the path of the file (${item.image_path} in the example), without the filename and extension?

Sth like $file->page()->url() ?
From the Docs

Maybe the most convenient solution: you could render the entire srcset attribute using $file->srcset().

If you want to do it manually, you could use $file->url() as a string and use either the methods in the Url class or PHP’s pathinfo().

Third pointer would be this plugin that might do some of the stuff for you: https://github.com/bnomei/kirby3-srcset

Maybe the most convenient solution: you could render the entire srcset attribute using $file->srcset() .

Thanks!