From 257fc2a9090996061b801a42910022026bc874a6 Mon Sep 17 00:00:00 2001 From: Titor Date: Wed, 10 Feb 2021 20:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/file.js | 5 +++-- extend/file.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/extend/file.js b/extend/file.js index 33536ab..120e562 100644 --- a/extend/file.js +++ b/extend/file.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.file = void 0; var fs_1 = require("fs"); +var path_1 = require("path"); /** * 文件操作类 * @description 更加语义化的简便文件操作。 @@ -19,9 +20,9 @@ var file = /** @class */ (function () { */ file.createPath = function (filePath) { // 获取完整目录(去除最后一位的文件字段) - var dir = filePath.substring(0, filePath.lastIndexOf("/")); + var dir = filePath.substring(0, filePath.lastIndexOf(path_1.sep)); if (dir == "" || dir == null) - dir = "./"; // 不写目录名 => 根目录 + dir = "." + path_1.sep; // 不写目录名 => 根目录 // 文件夹不存在 if (!fs_1.existsSync(dir)) { var actionNotice = fs_1.mkdirSync(dir, { recursive: true }); diff --git a/extend/file.ts b/extend/file.ts index 7c866a8..e6a1d59 100644 --- a/extend/file.ts +++ b/extend/file.ts @@ -1,5 +1,5 @@ import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "fs"; - +import { sep } from "path"; /** * 文件操作类 * @description 更加语义化的简便文件操作。 @@ -15,8 +15,8 @@ class file { */ protected static createPath(filePath: string): boolean { // 获取完整目录(去除最后一位的文件字段) - let dir = filePath.substring(0, filePath.lastIndexOf("/")); - if (dir == "" || dir == null) dir = "./"; // 不写目录名 => 根目录 + let dir = filePath.substring(0, filePath.lastIndexOf(sep)); + if (dir == "" || dir == null) dir = `.${sep}`; // 不写目录名 => 根目录 // 文件夹不存在 if (!existsSync(dir)) {