Skip to content

Latest commit

 

History

History
16 lines (11 loc) · 449 Bytes

get-folder-path-from-file-path.md

File metadata and controls

16 lines (11 loc) · 449 Bytes

How to extract a folder path from a file path with Node.js

Instead of using RegExp, substring, and replace, you can use the nodejs path module and the dirname method:

import path from 'path';

function getFolderPath(filePath: string): string {
    return path.dirname(filePath);
}

getOutputPath('C:\\source\\git\\.gitignore'); // C:\\source\\git

References: