# 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

```typescript
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

```typescript
// 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
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seanime.gitbook.io/seanime-extensions/plugins/apis/system/filepath.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
