UNPKG

fswin32

Version:

The ultimate Node.js module for detailed Windows file system access.

44 lines (39 loc) 1.39 kB
// src/symlinks.js import { promises as fs } from 'fs'; import { executePowerShellCommand } from './utils.js'; /** * Creates a symbolic link. * @param {string} source The path where the symbolic link will be created. * @param {string} destination The path that the symbolic link will point to. * @param {boolean} isDirectory Whether the destination is a directory. * @returns {Promise<string|null>} The result of the command. */ export const createSymbolicLink = async (source, destination, isDirectory = false) => { const command = isDirectory ? `mklink /D "${source}" "${destination}"` : `mklink "${source}" "${destination}"`; return await executePowerShellCommand(command); }; /** * Checks if a path is a symbolic link. * @param {string} path The path to check. * @returns {Promise<boolean>} True if the path is a symbolic link, false otherwise. */ export const isSymbolicLink = async (path) => { try { const stats = await fs.lstat(path); return stats.isSymbolicLink(); } catch (error) { return false; } }; /** * Reads the target of a symbolic link. * @param {string} path The path of the symbolic link. * @returns {Promise<string|null>} The target of the symbolic link. */ export const readSymbolicLink = async (path) => { try { return await fs.readlink(path); } catch (error) { return null; } };