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: