2024-10-05 11:53:35 +02:00
|
|
|
export default function getDirectoryFromPath(
|
|
|
|
filePath: string,
|
|
|
|
popFileName: boolean = true,
|
|
|
|
): string {
|
2024-04-24 21:29:51 +02:00
|
|
|
// Define the path separator based on the operating system
|
|
|
|
const separator = filePath.includes("/") ? "/" : "\\";
|
|
|
|
|
|
|
|
// Split the file path by the path separator
|
|
|
|
const pathParts = filePath.split(separator);
|
|
|
|
|
2024-10-05 11:53:35 +02:00
|
|
|
// Remove the last element to get the directory if popFileName is true
|
|
|
|
if (popFileName) pathParts.pop();
|
2024-04-24 21:29:51 +02:00
|
|
|
|
|
|
|
// Join the remaining parts back together to form the directory path
|
|
|
|
const directoryPath = pathParts.join(separator);
|
|
|
|
|
|
|
|
return directoryPath || "";
|
|
|
|
}
|