fswin32
Version:
The ultimate Node.js module for detailed Windows file system access.
34 lines (29 loc) • 1.25 kB
JavaScript
// src/permissions.js
import { executePowerShellCommand } from './utils.js';
/**
* Gets the permissions of a file or folder.
* @param {string} path The absolute path of the file or folder.
* @returns {Promise<string|null>} The permissions of the file or folder.
*/
export const getPermissions = async (path) => {
return await executePowerShellCommand(`icacls "${path}"`);
};
/**
* Sets the permissions of a file or folder.
* @param {string} path The absolute path of the file or folder.
* @param {string} user The user to set the permissions for.
* @param {string} permissions The permissions to set (e.g., 'F', 'M', 'RX').
* @returns {Promise<string|null>} The result of the command.
*/
export const setPermissions = async (path, user, permissions) => {
return await executePowerShellCommand(`icacls "${path}" /grant ${user}:${permissions}`);
};
/**
* Takes ownership of a file or folder.
* @param {string} path The absolute path of the file or folder.
* @returns {Promise<string|null>} The result of the command.
*/
export const takeOwnership = async (path) => {
const username = process.env.USERNAME;
return await executePowerShellCommand(`takeown /f "${path}" && icacls "${path}" /grant ${username}:F`);
};