### Install Example App Dependencies and Run Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Navigate to the example application directory, install its dependencies, and then run the Tauri development server. ```shell cd examples/tauri-app pnpm install pnpm tauri dev ``` -------------------------------- ### Install Project Dependencies and Build Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Install the necessary Node.js dependencies and build the project. This is typically done before running the example application. ```shell pnpm install pnpm build ``` -------------------------------- ### Install JavaScript Guest Bindings Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Install the JavaScript bindings for the plugin using your preferred package manager. This allows your frontend to interact with the plugin's APIs. ```shell pnpm add tauri-plugin-fs-pro-api ``` -------------------------------- ### Clone the Plugin Repository Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Clone the tauri-plugin-fs-pro repository from GitHub to access the source code and examples. ```shell git clone https://github.com/ayangweb/tauri-plugin-fs-pro.git ``` -------------------------------- ### Initialize tauri-plugin-fs-pro in Tauri App Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Integrate the plugin into your Tauri application by calling the `init()` function in your `lib.rs` file. This ensures the plugin is loaded when the application starts. ```rust pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_fs_pro::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } ``` -------------------------------- ### fullName - Get Complete File Name with Extension Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the complete file name including the extension. For directories, returns the directory name. ```APIDOC ## fullName - Get Complete File Name with Extension ### Description Returns the complete file name including the extension. For directories, returns the directory name. ### Method `fullName(path: string): Promise` ### Endpoint N/A (Client-side function) ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file or directory. ### Request Example ```typescript import { fullName } from "tauri-plugin-fs-pro-api"; const full = await fullName("/Users/username/Documents/report.pdf"); console.log(full); // "report.pdf" ``` ### Response #### Success Response (200) - **fullName** (string) - The complete file name or directory name. ``` -------------------------------- ### name - Get Base Name Without Extension Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Extracts the file or directory name without the extension from a given path. ```APIDOC ## name ### Description Extracts the file or directory name without the extension from a given path. ### Method `POST` (or relevant Tauri command invocation) ### Endpoint `plugin:fs-pro/name` ### Parameters #### Query Parameters - **path** (string) - Required - The path to extract the name from. ### Request Example ```json { "path": "/Users/username/Documents/report.pdf" } ``` ### Response #### Success Response (200) - **result** (string) - The base name of the file or directory without its extension. #### Response Example ```json { "result": "report" } ``` ``` -------------------------------- ### extname - Get File Extension Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Retrieves the file extension without the leading dot. Returns an empty string for directories or files without extensions. ```APIDOC ## extname - Get File Extension ### Description Returns the extension of the file without the leading dot. Returns an empty string for directories or files without extensions. ### Method `extname(path: string): Promise` ### Endpoint N/A (Client-side function) ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file. ### Request Example ```typescript import { extname } from "tauri-plugin-fs-pro-api"; const ext = await extname("/Users/username/Documents/report.pdf"); console.log(ext); // "pdf" ``` ### Response #### Success Response (200) - **ext** (string) - The file extension (e.g., "pdf", "jpg") or an empty string. ``` -------------------------------- ### Extract tar.gz Archive with tauri-plugin-fs-pro Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Extracts the contents of a tar.gz archive to a specified destination directory. Includes examples for basic extraction, error handling, and a restore workflow. ```typescript import { decompress } from "tauri-plugin-fs-pro-api"; // Basic decompression await decompress( "/Users/username/Backups/my-project.tar.gz", "/Users/username/Restored/my-project" ); ``` ```typescript // Extract to current user's downloads await decompress( "/path/to/archive.tar.gz", "/Users/username/Downloads/extracted" ); ``` ```typescript // With error handling try { await decompress( "/path/to/backup.tar.gz", "/path/to/restore/location" ); console.log("Extraction complete!"); } catch (error) { console.error("Failed to extract archive:", error); } ``` ```typescript // Restore workflow example import { isExist, metadata } from "tauri-plugin-fs-pro-api"; const archivePath = "/backups/project-backup.tar.gz"; const restorePath = "/restored/project"; if (await isExist(archivePath)) { const archiveInfo = await metadata(archivePath); console.log(`Extracting archive (${archiveInfo.size} bytes)...`); await decompress(archivePath, restorePath); const restoredSize = await size(restorePath); // Assuming 'size' is imported or defined elsewhere console.log(`Restored ${restoredSize} bytes to ${restorePath}`); } ``` -------------------------------- ### Get Size of Path with size Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt The `size` function calculates the size of a file in bytes or the total size of a directory's contents recursively. It returns 0 if the path does not exist. Includes an example of formatting bytes for display. ```typescript import { size } from "tauri-plugin-fs-pro-api"; // Get file size const fileSize = await size("/Users/username/Documents/report.pdf"); console.log(fileSize); // 1048576 (1 MB in bytes) // Get directory size (recursive) const dirSize = await size("/Users/username/Documents"); console.log(dirSize); // 5368709120 (5 GB in bytes) // Format size for display function formatBytes(bytes: number): string { const units = ['B', 'KB', 'MB', 'GB', 'TB']; let unitIndex = 0; while (bytes >= 1024 && unitIndex < units.length - 1) { bytes /= 1024; unitIndex++; } return `${bytes.toFixed(2)} ${units[unitIndex]}`; } const sizeInBytes = await size("/Users/username/Downloads"); console.log(formatBytes(sizeInBytes)); // "2.34 GB" ``` -------------------------------- ### Get Complete File Name with fullName Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the complete file name including the extension. For directories, it returns the directory name. Useful for displaying file lists. ```typescript import { fullName } from "tauri-plugin-fs-pro-api"; // Get full name of a file const full = await fullName("/Users/username/Documents/report.pdf"); console.log(full); // "report.pdf" // Get full name of a directory const dirFull = await fullName("/Users/username/Documents/my-project"); console.log(dirFull); // "my-project" // Use for displaying file lists const files = [ "/path/to/document.docx", "/path/to/image.png", "/path/to/archive.zip" ]; for (const file of files) { const displayName = await fullName(file); console.log(`- ${displayName}`); } // Output: // - document.docx // - image.png // - archive.zip ``` -------------------------------- ### parentName - Get Parent Directory Name Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the name of the parent directory at a specified level. The level parameter defaults to 1. ```APIDOC ## parentName - Get Parent Directory Name ### Description Returns the name of the parent directory at a specified level. The level parameter (defaults to 1) specifies how many levels up to traverse. ### Method `parentName(path: string, level?: number): Promise` ### Endpoint N/A (Client-side function) ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file or directory. - **level** (number) - Optional - The number of levels to traverse up from the current path. Defaults to 1. ### Request Example ```typescript import { parentName } from "tauri-plugin-fs-pro-api"; const parent = await parentName("/Users/username/Documents/report.pdf"); console.log(parent); // "Documents" const grandparent = await parentName("/Users/username/Documents/report.pdf", 2); console.log(grandparent); // "username" ``` ### Response #### Success Response (200) - **parentName** (string) - The name of the parent directory at the specified level. ``` -------------------------------- ### Get File Metadata with tauri-plugin-fs-pro Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Retrieves detailed metadata for a file or directory. Use the `omitSize` option for faster retrieval when file size is not needed, especially for large directories. ```typescript import { metadata, Metadata } from "tauri-plugin-fs-pro-api"; // Get full metadata for a file const fileMetadata: Metadata = await metadata("/Users/username/Documents/report.pdf"); console.log(fileMetadata); // { // size: 1048576, // name: "report", // extname: "pdf", // fullName: "report.pdf", // parentName: "Documents", // isExist: true, // isFile: true, // isDir: false, // isSymlink: false, // isAbsolute: true, // isRelative: false, // accessedAt: 1704067200000, // createdAt: 1703980800000, // modifiedAt: 1704153600000 // } ``` ```typescript // Get metadata without calculating size (faster for large directories) const quickMetadata = await metadata("/Users/username/LargeFolder", { omitSize: true }); console.log(quickMetadata.size); // 0 (omitted for performance) ``` ```typescript // Use metadata for file info display const info = await metadata("/path/to/document.docx"); console.log(`File: ${info.fullName}`); console.log(`Size: ${(info.size / 1024).toFixed(2)} KB`); console.log(`Modified: ${new Date(info.modifiedAt).toLocaleString()}`); console.log(`Created: ${new Date(info.createdAt).toLocaleString()}`); console.log(`Type: ${info.isDir ? 'Directory' : 'File'}`); ``` ```typescript // Check file properties const meta = await metadata("/some/path"); if (meta.isSymlink) { console.log("This is a symbolic link"); } if (meta.isRelative) { console.log("Path is relative"); } ``` -------------------------------- ### metadata - Get Comprehensive File Metadata Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Retrieves detailed metadata for a given file or directory. This includes size, timestamps, path components, and various type flags. ```APIDOC ## metadata - Get Comprehensive File Metadata ### Description Returns detailed metadata about a file or directory, including size, timestamps, path information, and type flags. ### Method `metadata(path: string, options?: { omitSize?: boolean }): Promise` ### Endpoint N/A (This is a function call within the Tauri application) ### Parameters #### Path Parameters - **path** (string) - Required - The absolute or relative path to the file or directory. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { metadata, Metadata } from "tauri-plugin-fs-pro-api"; // Get full metadata for a file const fileMetadata: Metadata = await metadata("/Users/username/Documents/report.pdf"); console.log(fileMetadata); // Get metadata without calculating size (faster for large directories) const quickMetadata = await metadata("/Users/username/LargeFolder", { omitSize: true }); console.log(quickMetadata.size); // 0 (omitted for performance) ``` ### Response #### Success Response (200) - **Metadata** (object) - An object containing file metadata. - **size** (number) - The size of the file in bytes. Omitted if `omitSize` is true. - **name** (string) - The base name of the file or directory without the extension. - **extname** (string) - The file extension (e.g., '.pdf', '.txt'). - **fullName** (string) - The full name of the file or directory, including the extension. - **parentName** (string) - The name of the parent directory. - **isExist** (boolean) - Whether the file or directory exists. - **isFile** (boolean) - Whether the path points to a file. - **isDir** (boolean) - Whether the path points to a directory. - **isSymlink** (boolean) - Whether the path points to a symbolic link. - **isAbsolute** (boolean) - Whether the path is absolute. - **isRelative** (boolean) - Whether the path is relative. - **accessedAt** (number) - Timestamp of the last access (in milliseconds). - **createdAt** (number) - Timestamp of the creation date (in milliseconds). - **modifiedAt** (number) - Timestamp of the last modification (in milliseconds). #### Response Example ```json { "size": 1048576, "name": "report", "extname": "pdf", "fullName": "report.pdf", "parentName": "Documents", "isExist": true, "isFile": true, "isDir": false, "isSymlink": false, "isAbsolute": true, "isRelative": false, "accessedAt": 1704067200000, "createdAt": 1703980800000, "modifiedAt": 1704153600000 } ``` ``` -------------------------------- ### size - Get Size of Path Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the size of a file or directory in bytes. For directories, it calculates the total size of all contents recursively. Returns 0 if the path does not exist. ```APIDOC ## size ### Description Returns the size of a file or directory in bytes. For directories, it calculates the total size of all contents recursively. Returns 0 if the path does not exist. ### Method `POST` (or relevant Tauri command invocation) ### Endpoint `plugin:fs-pro/size` ### Parameters #### Query Parameters - **path** (string) - Required - The path to get the size of. ### Request Example ```json { "path": "/Users/username/Documents/report.pdf" } ``` ### Response #### Success Response (200) - **result** (number) - The size of the file or directory in bytes. #### Response Example ```json { "result": 1048576 } ``` ``` -------------------------------- ### getDefaultSaveIconPath - Get Default Icon Save Location Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the default path where extracted icons are cached. This is typically within the app's data directory. ```APIDOC ## getDefaultSaveIconPath - Get Default Icon Save Location ### Description Returns the default path where extracted icons are cached. This is typically within the app's data directory. ### Method `getDefaultSaveIconPath(): Promise` ### Endpoint N/A (Client-side function) ### Parameters None ### Request Example ```typescript import { getDefaultSaveIconPath } from "tauri-plugin-fs-pro-api"; const iconSavePath = await getDefaultSaveIconPath(); console.log(iconSavePath); ``` ### Response #### Success Response (200) - **iconSavePath** (string) - The default path for cached icons. ``` -------------------------------- ### Get Parent Directory Name with parentName Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the name of the parent directory at a specified level. The level parameter defaults to 1. Useful for breadcrumb navigation. ```typescript import { parentName } from "tauri-plugin-fs-pro-api"; // Get immediate parent directory name const parent = await parentName("/Users/username/Documents/report.pdf"); console.log(parent); // "Documents" // Get parent at level 2 (grandparent) const grandparent = await parentName("/Users/username/Documents/report.pdf", 2); console.log(grandparent); // "username" // Get parent at level 3 const greatGrandparent = await parentName("/Users/username/Documents/report.pdf", 3); console.log(greatGrandparent); // "Users" // Useful for breadcrumb navigation const path = "/home/user/projects/myapp/src/components/Button.tsx"; const breadcrumbs = []; for (let i = 1; i <= 4; i++) { breadcrumbs.push(await parentName(path, i)); } console.log(breadcrumbs); // ["components", "src", "myapp", "projects"] ``` -------------------------------- ### Get File Extension with extname Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Retrieves the file extension without the leading dot. Returns an empty string for directories or files without extensions. Useful for file type validation. ```typescript import { extname } from "tauri-plugin-fs-pro-api"; // Get extension from file const ext = await extname("/Users/username/Documents/report.pdf"); console.log(ext); // "pdf" // Get extension from image const imgExt = await extname("/path/to/photo.jpeg"); console.log(imgExt); // "jpeg" // Directory returns empty string const dirExt = await extname("/Users/username/Documents"); console.log(dirExt); // "" // Use for file type validation const allowedExtensions = ["jpg", "jpeg", "png", "gif"]; const uploadExt = await extname("/uploads/image.png"); if (allowedExtensions.includes(uploadExt.toLowerCase())) { console.log("Valid image file"); } ``` -------------------------------- ### Get Default Icon Save Path with getDefaultSaveIconPath Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Returns the default path where extracted icons are cached, typically within the app's data directory. Can be used to manage the icon cache. ```typescript import { getDefaultSaveIconPath } from "tauri-plugin-fs-pro-api"; // Get the default icon save path const iconSavePath = await getDefaultSaveIconPath(); console.log(iconSavePath); // macOS: "/Users/username/Library/Application Support/com.your.app/tauri-plugin-fs-pro/icons" // Windows: "C:\\Users\\username\\AppData\\Roaming\\com.your.app\\tauri-plugin-fs-pro\\icons" // Linux: "/home/username/.local/share/com.your.app/tauri-plugin-fs-pro/icons" // Use to manage icon cache import { isDir, size } from "tauri-plugin-fs-pro-api"; const iconPath = await getDefaultSaveIconPath(); if (await isDir(iconPath)) { const cacheSize = await size(iconPath); console.log(`Icon cache size: ${cacheSize} bytes`); } ``` -------------------------------- ### Get Base Name Without Extension with name Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Use the `name` function to extract the base name of a file or directory, excluding its extension. It handles paths with multiple dots and hidden files correctly. ```typescript import { name } from "tauri-plugin-fs-pro-api"; // Get name from file path const fileName = await name("/Users/username/Documents/report.pdf"); console.log(fileName); // "report" // Get name from directory path const dirName = await name("/Users/username/Documents/my-project"); console.log(dirName); // "my-project" // Handle files with multiple dots const complexName = await name("/path/to/archive.tar.gz"); console.log(complexName); // "archive.tar" // Get name from hidden files const hiddenName = await name("/Users/username/.gitignore"); console.log(hiddenName); // ".gitignore" ``` -------------------------------- ### Configure Plugin Permissions Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Define the necessary permissions for Tauri Plugin FS Pro in the src-tauri/capabilities/default.json file. ```json { "permissions": [ "fs-pro:default" ] } ``` -------------------------------- ### isExist - Check if a Path Exists Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Checks whether a given path exists on the filesystem. Returns `true` if the path exists, `false` otherwise. ```APIDOC ## isExist ### Description Checks whether a given path exists on the filesystem. Returns `true` if the path exists, `false` otherwise. ### Method `POST` (or relevant Tauri command invocation) ### Endpoint `plugin:fs-pro/isExist` ### Parameters #### Query Parameters - **path** (string) - Required - The path to check. ### Request Example ```json { "path": "/Users/username/Documents/report.pdf" } ``` ### Response #### Success Response (200) - **result** (boolean) - `true` if the path exists, `false` otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### Add tauri-plugin-fs-pro to Tauri Project Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Add the plugin to your Tauri project's Cargo.toml file. This is the first step to enable the plugin's functionality. ```shell cargo add tauri-plugin-fs-pro ``` -------------------------------- ### Create tar.gz Archive with tauri-plugin-fs-pro Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Compresses files or directories into a tar.gz archive. Supports filtering using `includes` and `excludes` options to selectively archive specific files or exclude unwanted ones. ```typescript import { compress } from "tauri-plugin-fs-pro-api"; // Basic compression of a directory await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/my-project.tar.gz" ); ``` ```typescript // Compress with specific files only (includes) await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/source-only.tar.tar.gz", { includes: ["src", "package.json", "tsconfig.json"] } ); ``` ```typescript // Compress excluding certain files/directories await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/clean-backup.tar.gz", { excludes: ["node_modules", ".git", "dist", ".env"] } ); ``` ```typescript // Combine includes and excludes await compress( "/path/to/project", "/path/to/backup.tar.gz", { includes: ["src", "public", "config"], excludes: ["src/tests", "public/temp"] } ); ``` ```typescript // Compress a single file await compress( "/Users/username/Documents/large-file.bin", "/Users/username/Backups/large-file.tar.gz" ); ``` ```typescript // Error handling try { await compress("/source/path", "/dest/archive.tar.gz"); console.log("Compression successful"); } catch (error) { console.error("Compression failed:", error); } ``` -------------------------------- ### compress - Create tar.gz Archive Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Compresses a specified file or directory into a tar.gz archive. It supports filtering options to include or exclude specific files and directories. ```APIDOC ## compress - Create tar.gz Archive ### Description Compresses a directory or file into a tar.gz archive. Supports filtering with includes/excludes options. ### Method `compress(source: string, destination: string, options?: { includes?: string[], excludes?: string[] }): Promise` ### Endpoint N/A (This is a function call within the Tauri application) ### Parameters #### Path Parameters - **source** (string) - Required - The path to the file or directory to compress. - **destination** (string) - Required - The path where the compressed archive will be saved. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { compress } from "tauri-plugin-fs-pro-api"; // Basic compression of a directory await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/my-project.tar.gz" ); // Compress with specific files only (includes) await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/source-only.tar.gz", { includes: ["src", "package.json", "tsconfig.json"] } ); // Compress excluding certain files/directories await compress( "/Users/username/Documents/my-project", "/Users/username/Backups/clean-backup.tar.gz", { excludes: ["node_modules", ".git", "dist", ".env"] } ); // Combine includes and excludes await compress( "/path/to/project", "/path/to/backup.tar.gz", { includes: ["src", "public", "config"], excludes: ["src/tests", "public/temp"] } ); // Compress a single file await compress( "/Users/username/Documents/large-file.bin", "/Users/username/Backups/large-file.tar.gz" ); // Error handling try { await compress("/source/path", "/dest/archive.tar.gz"); console.log("Compression successful"); } catch (error) { console.error("Compression failed:", error); } ``` ### Response #### Success Response (200) - **void** - Indicates successful compression. #### Response Example None (This function returns void on success) ``` -------------------------------- ### icon - Extract File/Directory Icon Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Extracts the system icon for a file or directory and saves it as a PNG file. Returns the path to the saved icon. Icons are cached by file type for performance. ```APIDOC ## icon - Extract File/Directory Icon ### Description Extracts the system icon for a file or directory and saves it as a PNG file. Returns the path to the saved icon. Icons are cached by file type for performance. ### Method `icon(path: string, options?: { size?: number; savePath?: string }): Promise` ### Endpoint N/A (Client-side function) ### Parameters #### Path Parameters - **path** (string) - Required - The path to the file or directory. - **options** (object) - Optional - Configuration for icon extraction. - **size** (number) - Optional - The desired size of the icon in pixels (e.g., 32, 64, 128, 256, 512). Defaults to 32. - **savePath** (string) - Optional - A custom directory path to save the icon. If not provided, the default cache location is used. ### Request Example ```typescript import { icon } from "tauri-plugin-fs-pro-api"; // Get icon with default settings (32x32) const iconPath = await icon("/Users/username/Documents/report.pdf", {}); console.log(iconPath); // "/path/to/cached/pdf.png" // Get larger icon (512x512) const largeIconPath = await icon("/Users/username/Documents/report.pdf", { size: 512 }); // Custom save location const customIconPath = await icon("/path/to/file.txt", { size: 64, savePath: "/custom/icon/directory" }); ``` ### Response #### Success Response (200) - **iconPath** (string) - The path to the saved PNG icon file. ``` -------------------------------- ### Metadata Interface Reference Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt The `Metadata` interface provides detailed information about files and directories. It includes properties like size, name, type, timestamps, and existence status. Note that `size` is 0 if `omitSize` is true during the metadata retrieval. ```typescript interface Metadata { size: number; // Size in bytes (0 if omitSize is true) name: string; // File name without extension extname: string; // Extension without dot fullName: string; // Complete file name with extension parentName: string; // Parent directory name isExist: boolean; // Whether path exists isFile: boolean; // Whether path is a file isDir: boolean; // Whether path is a directory isSymlink: boolean; // Whether path is a symbolic link isAbsolute: boolean; // Whether path is absolute isRelative: boolean; // Whether path is relative accessedAt: number; // Last access time (Unix ms) createdAt: number; // Creation time (Unix ms) modifiedAt: number; // Last modified time (Unix ms) } ``` -------------------------------- ### Check if a Path Exists with isExist Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Use the `isExist` function from `tauri-plugin-fs-pro-api` to determine if a file or directory exists on the filesystem. It returns `true` if the path exists, and `false` otherwise. ```typescript import { isExist } from "tauri-plugin-fs-pro-api"; // Check if a file exists const fileExists = await isExist("/Users/username/Documents/report.pdf"); console.log(fileExists); // true // Check if a directory exists const dirExists = await isExist("/Users/username/Downloads"); console.log(dirExists); // true // Check a non-existent path const notFound = await isExist("/path/that/does/not/exist"); console.log(notFound); // false ``` -------------------------------- ### Extract File/Directory Icon with icon Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Extracts the system icon for a file or directory and saves it as a PNG. Returns the path to the saved icon. Icons are cached by file type. Supports custom size and save locations. ```typescript import { icon } from "tauri-plugin-fs-pro-api"; import { convertFileSrc } from "@tauri-apps/api/core"; // Get icon with default settings (32x32) const iconPath = await icon("/Users/username/Documents/report.pdf", {}); console.log(iconPath); // "/path/to/cached/pdf.png" // Get larger icon (512x512) const largeIconPath = await icon("/Users/username/Documents/report.pdf", { size: 512 }); // Custom save location const customIconPath = await icon("/path/to/file.txt", { size: 64, savePath: "/custom/icon/directory" }); // Display icon in Tauri app using convertFileSrc const filePath = "/Users/username/Downloads/package.zip"; const iconFilePath = await icon(filePath, { size: 128 }); const iconUrl = convertFileSrc(iconFilePath); // Use iconUrl in an tag: // Get application icon (macOS .app or Windows .exe) const appIconPath = await icon("/Applications/Safari.app", { size: 256 }); console.log(appIconPath); // Returns the actual app icon // Get directory icon const folderIconPath = await icon("/Users/username/Documents", { size: 64 }); console.log(folderIconPath); // Returns generic folder icon ``` -------------------------------- ### Metadata Interface Reference Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt The `Metadata` interface provides detailed information about a file or directory. ```APIDOC ## Metadata Interface ### Description Provides comprehensive file/directory information. ### Fields - **size** (number) - Size in bytes (0 if omitSize is true). - **name** (string) - File name without extension. - **extname** (string) - Extension without the leading dot. - **fullName** (string) - Complete file name with extension. - **parentName** (string) - Parent directory name. - **isExist** (boolean) - Whether the path exists. - **isFile** (boolean) - Whether the path is a file. - **isDir** (boolean) - Whether the path is a directory. - **isSymlink** (boolean) - Whether the path is a symbolic link. - **isAbsolute** (boolean) - Whether the path is absolute. - **isRelative** (boolean) - Whether the path is relative. - **accessedAt** (number) - Last access time in Unix milliseconds. - **createdAt** (number) - Creation time in Unix milliseconds. - **modifiedAt** (number) - Last modified time in Unix milliseconds. ``` -------------------------------- ### Check if Path is a File with isFile Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Use the `isFile` function to verify if a given path points to a regular file. It returns `true` for files and `false` for directories or non-existent paths. ```typescript import { isFile } from "tauri-plugin-fs-pro-api"; // Check a regular file const isRegularFile = await isFile("/Users/username/Documents/report.pdf"); console.log(isRegularFile); // true // Check a directory (returns false) const isDirectoryFile = await isFile("/Users/username/Documents"); console.log(isDirectoryFile); // false // Check non-existent path (returns false) const isNonExistent = await isFile("/path/does/not/exist.txt"); console.log(isNonExistent); // false ``` -------------------------------- ### Move Files and Directories with Transfer Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Use the `transfer` function to move files or directories. Supports filtering with `includes` and `excludes` options. Overwrites existing files by default. Ensure the source and destination paths are correctly specified. ```typescript import { transfer } from "tauri-plugin-fs-pro-api"; // Move entire directory contents await transfer( "/Users/username/Downloads/project", "/Users/username/Documents/projects" ); ``` ```typescript await transfer( "/Users/username/Downloads", "/Users/username/Documents/images", { includes: ["photo1.jpg", "photo2.png", "vacation.gif"] } ); ``` ```typescript await transfer( "/source/folder", "/destination/folder", { excludes: [".DS_Store", "Thumbs.db", ".gitkeep"] } ); ``` ```typescript await transfer( "/project/build", "/deploy/assets", { includes: ["bundle.js", "styles.css", "index.html"], excludes: ["bundle.js.map", "styles.css.map"] } ); ``` ```typescript import { isDir, metadata } from "tauri-plugin-fs-pro-api"; const downloadsPath = "/Users/username/Downloads"; const documentsPath = "/Users/username/Documents/PDFs"; await transfer(downloadsPath, documentsPath, { includes: ["report.pdf", "invoice.pdf", "contract.pdf"] }); console.log("PDF files moved to Documents"); ``` ```typescript try { await transfer("/source", "/destination", { excludes: ["temp", "cache"] }); console.log("Transfer complete"); } catch (error) { console.error("Transfer failed:", error); } ``` -------------------------------- ### Check if a Path Exists using JavaScript Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Use the `isExist` function from the plugin's JavaScript API to check if a given file path exists. This is a common utility for file system interactions. ```typescript import { isExist } from "tauri-plugin-fs-pro-api"; const exists = await isExist("/Users/xxx/EcoPaste.txt"); console.log(exists); // true ``` -------------------------------- ### isFile - Check if Path is a File Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Determines whether the given path points to a file (not a directory or symlink). Returns `true` if the path is a regular file. ```APIDOC ## isFile ### Description Determines whether the given path points to a file (not a directory or symlink). Returns `true` if the path is a regular file. ### Method `POST` (or relevant Tauri command invocation) ### Endpoint `plugin:fs-pro/isFile` ### Parameters #### Query Parameters - **path** (string) - Required - The path to check. ### Request Example ```json { "path": "/Users/username/Documents/report.pdf" } ``` ### Response #### Success Response (200) - **result** (boolean) - `true` if the path is a file, `false` otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### File Transfer API Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt The `transfer` function allows moving files and directories from a source path to a destination path. It supports filtering with `includes` and `excludes` options and overwrites existing files by default. This function is asynchronous and returns a Promise. ```APIDOC ## POST /api/fs-pro/transfer ### Description Moves files or directories from source to destination. Supports filtering with includes/excludes options. Overwrites existing files by default. ### Method POST ### Endpoint /api/fs-pro/transfer ### Parameters #### Request Body - **source** (string) - Required - The source path for the files or directories to be moved. - **destination** (string) - Required - The destination path where the files or directories will be moved. - **options** (object) - Optional - Configuration options for the transfer. - **includes** (array of strings) - Optional - An array of file names or patterns to include in the transfer. - **excludes** (array of strings) - Optional - An array of file names or patterns to exclude from the transfer. ### Request Example ```json { "source": "/Users/username/Downloads/project", "destination": "/Users/username/Documents/projects", "options": { "includes": ["photo1.jpg", "photo2.png"], "excludes": [".DS_Store"] } } ``` ### Response #### Success Response (200) - **message** (string) - Indicates the successful completion of the transfer operation. #### Response Example ```json { "message": "Transfer complete" } ``` #### Error Handling - **error** (string) - Describes the error that occurred during the transfer. ``` -------------------------------- ### isDir - Check if Path is a Directory Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Determines whether the given path points to a directory. Returns `true` if the path is a directory. ```APIDOC ## isDir ### Description Determines whether the given path points to a directory. Returns `true` if the path is a directory. ### Method `POST` (or relevant Tauri command invocation) ### Endpoint `plugin:fs-pro/isDir` ### Parameters #### Query Parameters - **path** (string) - Required - The path to check. ### Request Example ```json { "path": "/Users/username/Documents" } ``` ### Response #### Success Response (200) - **result** (boolean) - `true` if the path is a directory, `false` otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### Check if Path is a Directory with isDir Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Use the `isDir` function to determine if a path points to a directory. It returns `true` for directories and `false` for files or non-existent paths. This can be used for conditional logic. ```typescript import { isDir } from "tauri-plugin-fs-pro-api"; // Check a directory const isDirectory = await isDir("/Users/username/Documents"); console.log(isDirectory); // true // Check a file (returns false) const isFileDir = await isDir("/Users/username/Documents/report.pdf"); console.log(isFileDir); // false // Use for conditional logic const path = "/Users/username/Downloads"; if (await isDir(path)) { console.log("Path is a directory, can list contents"); } else { console.log("Path is not a directory"); } ``` -------------------------------- ### decompress - Extract tar.gz Archive Source: https://context7.com/ayangweb/tauri-plugin-fs-pro/llms.txt Extracts the contents of a tar.gz archive to a specified destination directory. Handles potential errors during the extraction process. ```APIDOC ## decompress - Extract tar.gz Archive ### Description Extracts a tar.gz archive to a specified destination directory. ### Method `decompress(source: string, destination: string): Promise` ### Endpoint N/A (This is a function call within the Tauri application) ### Parameters #### Path Parameters - **source** (string) - Required - The path to the tar.gz archive to extract. - **destination** (string) - Required - The directory where the archive contents will be extracted. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { decompress } from "tauri-plugin-fs-pro-api"; // Basic decompression await decompress( "/Users/username/Backups/my-project.tar.gz", "/Users/username/Restored/my-project" ); // Extract to current user's downloads await decompress( "/path/to/archive.tar.gz", "/Users/username/Downloads/extracted" ); // With error handling try { await decompress( "/path/to/backup.tar.gz", "/path/to/restore/location" ); console.log("Extraction complete!"); } catch (error) { console.error("Failed to extract archive:", error); } // Restore workflow example import { isExist, metadata, size } from "tauri-plugin-fs-pro-api"; const archivePath = "/backups/project-backup.tar.gz"; const restorePath = "/restored/project"; if (await isExist(archivePath)) { const archiveInfo = await metadata(archivePath); console.log(`Extracting archive (${archiveInfo.size} bytes)...`); await decompress(archivePath, restorePath); const restoredSize = await size(restorePath); // Assuming 'size' function is available console.log(`Restored ${restoredSize} bytes to ${restorePath}`); } ``` ### Response #### Success Response (200) - **void** - Indicates successful decompression. #### Response Example None (This function returns void on success) ``` -------------------------------- ### Add fs-pro Permission to Tauri Capabilities Source: https://github.com/ayangweb/tauri-plugin-fs-pro/blob/master/README.md Grant the necessary permissions for the fs-pro plugin in your Tauri application's capabilities configuration. This allows the plugin to perform its file system operations. ```json { ... "permissions": [ ... "fs-pro:default" ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.