windows network drive stuff
npm install windows-network-drivebash
$ npm install windows-network-drive
`
Features
* Mount a network drive that will persist after reboot
* Unmount a network drive
* Get a list of all network drives
* Find if a path is already mounted and get the drive letter
* Convert Unix paths to Windows friendly paths
* TypeScript types included
Methods
All examples assume:
`javascript
let networkDrive = require('windows-network-drive');
`
$3
Finds if a path is already mounted and returns all drive letters that point to that exact path.
`typescript
find(drivePath: string): Promise<{status: boolean, driveLetter: string, path: string, statusMessage: string}[]>
`
#### Examples
`javascript
networkDrive.find("\\\\DoesExist\\Path")
.then(function (result)
{
// result === [{status: true, driveLetter: "Z", path: "\\\\DoesExist\\Path", "statusMessage": "OK"}]
});
networkDrive.find("\\\\DoesExist\\Path\\ThisFolderIsNotPartOfTheMountPath")
.then(function (driveLetter)
{
// driveLetter === []
});
networkDrive.find("\\\\DoesNOTExist\\Path")
.then(function (driveLetter)
{
// driveLetter === []
});
`
$3
List all network drives and their paths.
`typescript
list(void): Promise`
#### Examples
`javascript
// With network drives
networkDrive.list()
.then(function (drives)
{
/*
drives = {
"F": { "status": true, "driveLetter": "F", "path": "\\\\NETWORKA\\Files", "statusMessage": "OK" },
"K": { "status": true, "driveLetter": "K", "path": "\\\\NETWORKB\\Files", "statusMessage": "OK" }
}
*/
});
// No network drives
networkDrive.list()
.then(function (drives)
{
// drives = {}
});
`
$3
Mounts a network drive path and returns the new drive letter.
`typescript
mount(drivePath: string, driveLetter?: string, username?: string, password?: string): Promise
`
#### Examples
`javascript
networkDrive.mount("\\\\DoesExist\\Path\\Files", "F", undefined, undefined)
.then(function (driveLetter)
{
// driveLetter = "F"
});
`
$3
Unmounts a network drive.
`typescript
unmount(driveLetter: string): Promise
`
#### Examples
`javascript
networkDrive.unmount("F")
.then(function ()
{
// done
});
`
$3
Converts a valid file system path to a Windows friendly path.
NOTE: All methods can take in a non Windows friendly path. This is exported for user convenience.
`typescript
pathToWindowsPath(drivePath: string): Promise
`
#### Examples
`javascript
networkDrive.pathToWindowsPath("//DoesExist/Path/Files")
.then(function (windowsPath)
{
// windowsPath = \\\\DoesExist\\Path\\Files
});
`
$3
Test the current OS is Windows.
`typescript
isWinOs(void): boolean
`
#### Examples
`javascript
if (true ===networkDrive.isWinOs())
{
console.log("This is running on Windows");
}
`
More Examples
For more examples, check out the example folder in the GitHub repo!
Tests
To run the test suite, first install the dependencies, then run npm test:
`bash
$ npm install
$ npm test
``