Filepath

$filepath

$filepath implements utility routines for manipulating filename paths in a way compatible with the target operating system-defined file paths.

Go reference: https://pkg.go.dev/path/filepath

Helpers

const baseName = $filepath.base("C:\Users\user\Downloads\file.mkv");
console.log(baseName); // file.mkv

const dirName = $filepath.dir("C:\Users\user\Downloads\file.mkv");
console.log(dirName); // C:\Users\user\Donwloads

const extName = $filepath.ext("C:\Users\user\Downloads\file.mkv");
console.log(extName); // .mkv

const joinedPath = $filepath.join("C:", "Users", "user", "subdir", "file.txt");
console.log(joinedPath); // C:\Users\user\subdir\file.txt

const [dir, file] = $filepath.split("C:\Users\user\Downloads\file.mkv");
console.log(dir, file); // C:\Users\user\Downloads, file.mkv

const globResults = $filepath.glob("C:\Users\user\Downloads", "*.txt");
console.log(globResults); // test.txt, test2.txt

const isMatch = $filepath.match("*.txt", "test.txt");
console.log(isMatch); // true

const isAbsPath = $filepath.isAbs("C:\Users\user\Downloads\file.mkv");
console.log(isAbsPath); // true

// Test toSlash and fromSlash
const slashPath = $filepath.toSlash("C:\Users\user\Downloads\file.mkv");
console.log(slashPath); // C:/Users/user/Downloads/file.mkv

const fromSlashPath = $filepath.fromSlash(slashPath);
console.log(fromSlashPath); // C:\Users\user\Downloads\file.mkv

Walk directories

Last updated