-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPSD.file.jsx
75 lines (68 loc) · 1.76 KB
/
PSD.file.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @author [email protected]
* @20130806 PSD
*
* 导出文件、读取文件等操作
* @depands:PSD.jsx
*/
#include "PSD.jsx"
PSD.file = {
/**
* 存储文件
* path 存储的文件路径
* text 存储的文件内容
* encoding 存储的文件编码,可选,当为空是默认 GBK
*/
write: function(path, text, encoding){
var f;
if (!encoding) {
encoding = "GBK";
}
f = new File(path);
f.encoding = encoding;
f.open('w');
f.write(text);
f.close();
return text;
},
/**
* 获取文件夹中的文件列表,包含子文件夹
* @path:路径
* @except []:需排除的文件
*/
getFilesList: function(path,except) {
var folder
, list = []
, leng
, p, i
, pList = []
;
folder = new Folder(path);
list = folder.getFiles();
leng = list.length;
for (i = 0; i < leng; i++) {
p = list[i];
if (Folder.prototype.isPrototypeOf(p)){
pList = pList.concat(this.getFilesList(p.absoluteURI));
} else {
pList.push(p);
}
}
if(except && except.length){
var exceptLoop = except.length;
var listLoop = pList.length;
var exceptName,listName;
for (var i = exceptLoop - 1; i >= 0; i--) {
exceptName = except[i];
for (var j = listLoop - 1; j >=0; j--) {
listName = pList[j]["name"];
if(listName === exceptName){
pList.splice(j,1);
break;
}
};
};
}
return pList;
}
};