mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 10:00:57 +00:00
Merge pull request #336 from gnh1201/dev
Add isAbsolutePath utility and update path handling
This commit is contained in:
commit
de08a5c527
22
lib/file.js
22
lib/file.js
|
|
@ -171,6 +171,24 @@ function loadEnvFromArgs(args, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
function normalizePath(path) {
|
||||
if (typeof path !== "string")
|
||||
return false;
|
||||
|
||||
return (function(s) {
|
||||
s = s.trim();
|
||||
return (s.charAt(0) === "\uFEFF" ? s.slice(1) : s);
|
||||
})(path);
|
||||
}
|
||||
|
||||
function isAbsolutePath(path) {
|
||||
var normalizedPath = normalizePath(path);
|
||||
|
||||
return (/^[a-zA-Z]:[\\/]/).test(normalizedPath) ||
|
||||
(/^[\\/]{2,}/).test(normalizedPath) ||
|
||||
(/^\//).test(normalizedPath);
|
||||
};
|
||||
|
||||
exports.fileExists = fileExists;
|
||||
exports.folderExists = folderExists;
|
||||
exports.fileGet = fileGet;
|
||||
|
|
@ -187,10 +205,12 @@ exports.appendFile = appendFile;
|
|||
exports.rotateFile = rotateFile;
|
||||
exports.loadEnvFromFile = loadEnvFromFile;
|
||||
exports.loadEnvFromArgs = loadEnvFromArgs;
|
||||
exports.normalizePath = normalizePath;
|
||||
exports.isAbsolutePath = isAbsolutePath;
|
||||
|
||||
exports.CdoCharset = PipeIPC.CdoCharset;
|
||||
|
||||
exports.VERSIONINFO = "File IO Library (file.js) version 0.2.15";
|
||||
exports.VERSIONINFO = "File IO Library (file.js) version 0.2.16";
|
||||
exports.AUTHOR = "gnh1201@catswords.re.kr";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ function Excel() {
|
|||
this.open = function(filename) {
|
||||
if (typeof filename !== "undefined") {
|
||||
// check type of the path
|
||||
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) {
|
||||
if (!FILE.isAbsolutePath(filename)) {
|
||||
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
|
||||
}
|
||||
if (FILE.fileExists(filename)) {
|
||||
|
|
@ -128,7 +128,7 @@ function PowerPoint() {
|
|||
this.open = function(filename) {
|
||||
if (typeof filename !== "undefined") {
|
||||
// check type of the path
|
||||
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) {
|
||||
if (!FILE.isAbsolutePath(filename)) {
|
||||
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
|
||||
}
|
||||
if (FILE.fileExists(filename)) {
|
||||
|
|
@ -210,7 +210,7 @@ function Word() {
|
|||
this.open = function(filename) {
|
||||
if (typeof filename !== "undefined") {
|
||||
// check type of the path
|
||||
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) {
|
||||
if (!FILE.isAbsolutePath(filename)) {
|
||||
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
|
||||
}
|
||||
if (FILE.fileExists(filename)) {
|
||||
|
|
@ -227,7 +227,7 @@ exports.Excel = Excel;
|
|||
exports.PowerPoint = PowerPoint;
|
||||
exports.Word = Word;
|
||||
|
||||
exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.2.1";
|
||||
exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.2.2";
|
||||
exports.AUTHOR = "gnh1201@catswords.re.kr";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user