1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | let pathInfo = (fileOrDirPath)=>{
|
9 | const {fs,path,tip} = {
|
10 | fs:require('fs'),
|
11 | path:require('path'),
|
12 | tip:require('./tip')
|
13 | };
|
14 |
|
15 | let info = {
|
16 | 'type':undefined,
|
17 | 'extension':undefined,
|
18 | 'name':undefined
|
19 | };
|
20 |
|
21 | try {
|
22 | let stat = fs.statSync(fileOrDirPath);
|
23 |
|
24 |
|
25 | if(stat.isDirectory()){
|
26 | info.type = 'dir';
|
27 |
|
28 | let backPath = path.resolve(fileOrDirPath,'../'),
|
29 | dirName = fileOrDirPath.replace(backPath,''),
|
30 | re = /[/]|[\\]/g;
|
31 |
|
32 | info.name = dirName.replace(re,'');
|
33 | };
|
34 |
|
35 |
|
36 | if(stat.isFile()){
|
37 | info.type = 'file';
|
38 | info.extension = path.extname(fileOrDirPath);
|
39 | info.name = path.basename(fileOrDirPath,info.extension);
|
40 | };
|
41 | } catch (error) {
|
42 |
|
43 | };
|
44 |
|
45 | return info;
|
46 | };
|
47 |
|
48 | module.exports = pathInfo;
|
49 |
|
50 |
|
51 |
|