🧩
Seanime Extensions
🧩
Seanime Extensions
  • Seanime
    • Getting started
    • Core APIs
    • Changelog
  • Content Providers
    • Write, test, share
    • Anime torrent provider
    • Manga provider
    • Online streaming provider
  • Plugins
    • Introduction
    • Write, test, share
    • APIs
      • Helpers
      • Store
      • Storage
      • Database
      • AniList
      • System
        • Permissions
        • OS
        • Filepath
        • Commands
        • Buffers, I/O
        • MIME
    • UI
      • Basics
      • User Interface
        • Tray
        • Toast
        • Screen
        • Command Palette
        • Action
        • DOM
      • Anime/Library
        • Anime
        • Playback
        • Continuity
        • Auto Downloader
        • Auto Scanner
        • Filler Manager
        • External Player Link
      • Downloading
        • Downloader
        • Torrent Client
      • Other
        • Manga
        • Discord
        • MPV
    • Hooks
    • Example
  • Frequently asked
    • Feature requests
Powered by GitBook
On this page
  • $filepath
  • Helpers
  • Walk directories
  1. Plugins
  2. APIs
  3. System

Filepath

PreviousOSNextCommands

Last updated 2 months ago

$filepath

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

Go reference:

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

// walk calls 'lstat' on each file path it encounters, which can be slower
$filepath.walk("C:\Users\user\Downloads", (path, info, err) => {
	if (err) {
		console.log("Walk error:", path, err);
		return; // Continue walking
	}
	
	// We can skip directories
	if (info.isDir() && info.name() === "ignoredDir") {
		console.log("Skipping directory:", path);
		return $filepath.skipDir;
	}
	
	console.log("Walk path:", path, "isDir:", info.isDir());
	return; // Continue walking
});

// walkDir is more efficient
$filepath.walkDir("C:\Users\user\Downloads", (path, d, err) => {
	if (err) {
		console.log("WalkDir error:", path, err);
		return; // Continue walking
	}
	
	// We can skip directories
	if (d.isDir() && d.name() === "ignoredDir") {
		console.log("Skipping directory:", path);
		return $filepath.skipDir;
	}
	
	console.log("WalkDir path:", path, "isDir:", d.isDir());
	return; // Continue walking
});
https://pkg.go.dev/path/filepath