i was looking everywhere to a way of remove only the filename of a path with JS, but I only find information of how to remove the path, and keep the filename. I have this path:
C:\Users\usuario\Desktop\CyT\Proyectos\AlmPas\2022-06-17\luis@gmail.com\1234567890.zip
But then, i only need the path:
C:\Users\usuario\Desktop\CyT\Proyectos\AlmPas\2022-06-17\luis@gmail.com\
If i use the next code, i get the filename only, but how can i get the path without the filename?
soloArchivo = ruta_archivos.replace(/^.*[\\\/]/, '')
Extract with this regular expression:
const str = String.raw`C:\Users\usuario\Desktop\CyT\Proyectos\AlmPas\2022-06-17\luis@gmail.com\1234567890.zip`
const regex = /^.*[\\\/]/;
const match = str.match(regex);
if (match) {
console.log(match[0])
} else {
console.log("Sorry, there is no match.")
}
Results: C:\Users\usuario\Desktop\CyT\Proyectos\AlmPas\2022-06-17\luis@gmail.com\
PATTERN EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
[\/] any character of: '\/'