Skip to content
/ WshPath Public

Adds useful functions (similar to Node.js path) that handles file path strings in WSH (Windows Script Host).

License

Notifications You must be signed in to change notification settings

tuckn/WshPath

Repository files navigation

WshPath

Adds useful functions (similar to Node.js path) that handle file path strings into WSH (Windows Script Host).

tuckn/Wsh series dependency

WshModeJs
└─ WshZLIB
 └─ WshNet
  └─ WshChildProcess
   └─ WshProcess
     └─ WshFileSystem
       └─ WshOS
         └─ WshPath - This repository
           └─ WshUtil
             └─ WshPolyfill

The upper layer module can use all the functions of the lower layer module.

Operating environment

Works on JScript in Windows.

Installation

(1) Create a directory of your WSH project.

D:\> mkdir MyWshProject
D:\> cd MyWshProject

(2) Download this ZIP and unzip or Use the following git command.

> git clone https://github.com/tuckn/WshPath.git ./WshModules/WshPath
or
> git submodule add https://github.com/tuckn/WshPath.git ./WshModules/WshPath

(3) Create your JScript (.js) file. For Example,

D:\MyWshProject\
├─ MyScript.js <- Your JScript code will be written in this.
└─ WshModules\
    └─ WshPath\
        └─ dist\
          └─ bundle.js

I recommend JScript (.js) file encoding to be UTF-8 [BOM, CRLF].

(4) Create your WSF packaging scripts file (.wsf).

D:\MyWshProject\
├─ Run.wsf <- WSH entry file
├─ MyScript.js
└─ WshModules\
    └─ WshPath\
        └─ dist\
          └─ bundle.js

And you should include .../dist/bundle.js into the WSF file. For Example, The content of the above Run.wsf is

<package>
  <job id = "run">
    <script language="JScript" src="./WshModules/WshPath/dist/bundle.js"></script>
    <script language="JScript" src="./MyScript.js"></script>
  </job>
</package>

I recommend this WSH file (.wsf) encoding to be UTF-8 [BOM, CRLF].

Awesome! This WSH configuration allows you to use the following functions in JScript (.\MyScript.js).

Usage

Now your JScript (.\MyScript.js ) can use helper functions to handle paths. For example,

var path = Wsh.Path; // Shorthand

console.log(__filename); // "D:\MyWshProject\Run.wsf"
console.log(__dirname); // "D:\MyWshProject"
console.log(path.delimiter); // ';"
console.log(path.sep); // "\"

path.dirname('C:\\My Data\\image.jpg'); // 'C:\\My Data'
path.basename('C:\\foo\\bar\\baz\\quux.html'); // 'quux.html'
path.extname('index.coffee.md'); // '.md'

path.parse('C:\\home\\user\\dir\\file.txt');
// Returns:
// { root: 'C:\\',
//   dir: 'C:\\home\\user\\dir',
//   base: 'file.txt',
//   ext: '.txt',
//   name: 'file' };

path.isAbsolute('C:\\My Data\\hoge.png'); // true
path.isAbsolute('bar\\baz'); // false
path.isAbsolute('.'); // false

path.normalize('C:\\Git\\mingw64\\lib\\..\\etc\\.gitconfig');
// Returns: 'C:\\Git\\mingw64\\etc\\.gitconfig'

path.join('mingw64\\lib', '..\\etc', '.gitconfig');
// Returns: 'mingw64\\etc\\.gitconfig'

path.resolve('mingw64\\lib', '..\\etc', '.gitconfig');
// Returns: '<Current Working Directory>\\mingw64\\etc\\.gitconfig'

path.isUNC('C:\\foo\\bar.baz'); // false
path.isUNC('\\\\CompName\\'); // false
path.isUNC('\\\\CompName\\SharedDir'); // true
path.isUNC('//CompName//SharedDir'); // false

path.toUNC('C:\\foo\\bar.baz');
// Returns: '\\\\<Your CompName>\\C$\\foo\\bar.baz'

var from = 'C:\\MyApps\\Paint\\Gimp';
var to = 'C:\\MyApps\\Converter\\ImageMagick\\convert.exe';
path.relative(from, to);
// Returns: '..\\..\\Converter\\ImageMagick\\convert.exe'

Many other functions will be added. See the documentation for more details.

Dependency Modules

You can also use the following helper functions in your JScript (.\MyScript.js).

Documentation

See all specifications here and also below.

License

MIT

Copyright (c) 2020 Tuckn

About

Adds useful functions (similar to Node.js path) that handles file path strings in WSH (Windows Script Host).

Resources

License

Stars

Watchers

Forks

Packages

No packages published