specpress
Version:
Export PDF and/or DOCX files from a subset of Markdown, ASN.1 and JSON files
26 lines (20 loc) • 630 B
JavaScript
import { dirname, normalize } from "path";
import { stat } from "fs/promises";
export async function getFolderPath(pathFiile) {
// Normalize the path to handle any relative paths or extra slashes
const normalizedPath = normalize(pathFiile);
let directoryPath;
try {
const stats = await stat(normalizedPath);
if (stats.isFile()) {
return dirname(normalizedPath);
} else if (stats.isDirectory()) {
return normalizedPath;
} else {
throw new Error(`Error checking path`);
}
} catch (error) {
throw new Error(`Error checking path: ${error.message}`);
}
return directoryPath;
}