npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

windows-fs

v1.2.0

Published

Windows utilities when working with the file system

Downloads

522

Readme

windows-fs

:cyclone: Windows utilities when working with the file system. Intended for use with electron or nodejs.

NPM version Dependency Status License Js Standard Style

Installation

npm install windows-fs

Example

import { mount, statByDriveLetter } from 'windows-fs'

mount('server', 'share')
  .then(letter => statByDriveLetter(letter))
  .then(log)
// -> { freeSpace: 10700152832, size: 53579083776 }

Note that all paths are written in unix style format to ease the developer pain from double escaping the backslash in windows. All other path characteristics stay the same (a:/, //server).

API

isMounted

Checks if a given unc path is already mounted. If it's mounted returns the drive letter otherwise returns undefined.

Parameters

  • unc String Unc like path server/share$

Examples

isMounted('server/share$')
  .then((letter) => {
    // mounted network drive hasn't been found
    if (!letter) return
    // found
  })

Returns (String|undefined) The drive letter or if not found undefined

mount

Mounts a network drive to the next available drive letter and returns a the drive letter which it was mounted on.

Parameters

  • unc String A UNC path like //server
  • path String A path like some/path/to/folder
  • credentials Object= user and password to log into a network

Examples

// (given letter Y: is free)
mount('server', 'c$')
  .then(log)
  .catch((err) => console.error('failed to mount', err))
// -> Y:

Returns Promise Resolves to the drive letter which the path was mounted on, rejects when the command fails

mountedDrives

Gets a list of mounted drive letters and their respective unc paths.

Returns Array Array of { unc, letter } tuples

statByDriveLetter

Gets stats by a given drive letter like the current size of the hdd etc. This also works for drives in a network. Use statDrives() when their are no login credentials, otherwise use this function to avoid firewall settings.

Parameters

  • letter String The drive letter which the hdd was mounted on

Examples

statByDriveLetter('Z:')
// -> { freeSpace: 10700152832, size: 53579083776 }

Returns Promise A promise which resolves to { freeSpace, size }

statDirectory

Gets various metadata about the directory and the files in it using a recursive walk.

Parameters

Examples

statDirectory('c:/temp/log')
// -> { count: 4, size: 32636 }

Returns Object Object with size (directory size in bytes), count (file count) and files (list of files in the directory and their respective metadata)

statDrives

Gets various information about all the drives mounted on a given computer

Parameters

Examples

statDrives('computer-name').then(log)
// -> [{ deviceID: 'C:', freeSpace: 4324564, ...}, ...]

Returns Promise Resolves to { json, stdout, stderr }

toUncPath

Creates a windows path given a server name and a unix path.

Parameters

Examples

toUncPath('server', 'some/path/to/a/log')
// -> `\\server\some\path\to\a\log`

toWindowsPath

Replaces / with \ so we can use an unix path and convert it to a windows path.

Parameters

Examples

toWindowsPath('some/random/folder')
// -> some\random\folder

Returns String Windows style path

unmount

Unmounts a network drive given a letter and returns the letter.

Parameters

  • letter String Network drive letter

Examples

// (given letter Z: is mounted)
unmount('Z:')
  .then(log)
  .catch((err) => console.error('failed to unmount', err))
// -> Z:

Returns Promise Resolves to the drive letter when successful, rejects when the command fails

Tests

There is an extensive test suite which is not generalized for public tests because its not independent of the system it's running on. We haven't found a way to get around that for windows-like utilities.

npm test

License

MIT