Skip to content

convertPath

xiao edited this page Nov 8, 2025 · 1 revision

converts paths between 8.3 name and long name. these functions require a filesystem or network I/O, so there are both a block and a non-block version.

usage

callback:

fswin.convertPath(pathToConvert, callback, [isLong]);

async:

var result = await fswin.convertPathAsync(pathToConvert, [isLong]);

sync:

var result = fswin.convertPathSync(pathToConvert, [isLong]);
  • pathToConvert is a string that specifies the path to convert.
  • callback is a function that takes only one argument result.
  • isLong is a boolean value to determine the result will be a long or a short path. default value is false.
  • result is a string to indicate the converted path or null when failed.

example

var fswin = require('fswin');
var paths = ['C:\\PROGRA~1', 'C:\\program files\\Common Files', '\\\\mycomputer\\sharefolder\\somedir\\anotherdir', 'c:\\', '\\\\mycomputer\\sharefolder\\somedir', '\\\\mycomputer\\sharedfolder\\'];
var i;
//test the sync version
//note: if the path does not exist, this function will return an empty string.
for (i = 0; i < paths.length; i++) {
	console.log('the long name of "' + paths[i] + '" is: "' + fswin.convertPathSync(paths[i], true) + '" and its short name is "' + fswin.convertPathSync(paths[i]) + '"');
}
//test the async version
//note: this function returns false before the async call if error occurs
for (i = 0; i < paths.length; i++) {
	if (fswin.convertPath(paths[i], function (result) {
		this.convertPath(result, function (result2) {
			console.log('short name: "' + result + '" long name: "' + result2 + '"');
		}, true);
	})) {
		console.log('the async call will be called');
	} else {
		console.log('there is an unexpected error, the async call will not be called.');
	}
}

Clone this wiki locally