-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.js
More file actions
172 lines (146 loc) · 3.88 KB
/
FileSystem.js
File metadata and controls
172 lines (146 loc) · 3.88 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// ************************************************************************
// Work with File system and files
// ************************************************************************
var FileSystem = function ()
{
// ************************************************************************
//_private
// ************************************************************************
// ************************************************************************
//public
// ************************************************************************
this._FSO = new ActiveXObject("Scripting.FileSystemObject");
}
/**
*
* @param {String} folderpath
* @returns {Boolean}
*/
FileSystem.prototype.FolderExsists = function (folderpath) {
return this._FSO.FolderExists(folderpath)
}
/**
*
* @param {String} path
* @returns {Boolean}
*/
FileSystem.prototype.FileExsists = function (path) {
return this._FSO.FileExists(path)
}
/**
*
* @param {String} path
* @returns {Boolean}
* @throws {Error}
*/
FileSystem.prototype.FolderCreate = function (path) {
var answer =false;
try {
this._FSO.CreateFolder(path);
answer = true;
}
catch (e) {
throw new Error("Error Create Folder");
}
finally {
return answer;
}
}
/**
*
* @param {String} source
* @param {String} destination
* @param {Boolean} overwrite
* @returns {String Boolean} dest
* @throws {Error}
*/
FileSystem.prototype.CopyFile = function (source, destination, overwrite) {
var answer = false;
try {
//check
if (!this.FileExsists(source)) {throw new Error("File "+source+" Not Exist")};
if (destination[destination.length - 1] == "/") destination += "default";
if (this.FileExsists(destination)) {
var Words_Array = destination.split(/\./);
var type=Words_Array[Words_Array.length - 1]
destination = "\." + Words_Array.slice(0, Words_Array.length - 1).join("") + this.CreateTimeFileName() + "\." + type;
};
//copy
this._FSO.CopyFile(source, destination, overwrite);
answer = true;
}
catch (e) {
alert(e.message);
throw new Error(e.message);
}
finally {
return { dest: destination, answer: answer };
}
}
/**
*
* @param source
*/
FileSystem.prototype.GetFolder = function (source)
{
try {
if (this.FolderExsists(source)) {
return this._FSO.GetFolder(source);
}
} catch (e) {
alert(e.message);
throw new Error(e.message);
}
}
/**
*
* @param source
* @description delete and check file from source
*/
FileSystem.prototype.DeleteFile = function (source)
{
try{
if (this.FileExsists(source))
{
this._FSO.DeleteFile(source);
}
} catch (e) {
alert(e.message);
throw new Error(e.message);
}
}
/**
*
* @param source
* @param recursive
*/
FileSystem.prototype.DeleteFolder = function (source, recursive)
{
try {
if (this.FolderExsists(source)) {
this._FSO.DeleteFolder(source);
}
} catch (e) {
alert(e.message);
throw new Error(e.message);
}
}
/**
* @returns {String}
* @description format YYYY_MM_DD_timeHH_SS
*/
FileSystem.prototype.CreateTimeFileName = function () {
var time = new Date();
var time_year = time.getFullYear();
var time_mounth = time.getMonth() + 1;
var time_day = time.getDate();
var time_min = time.getMinutes();
var time_hours = time.getHours();
var time_sec = time.getSeconds();
var time_wr = time_year + "" + time_mounth + "" + time_day + "time"
time_wr += ((time_hours < 10) ? "0" : "") + time_hours;
time_wr += "";
time_wr += ((time_min < 10) ? "0" : "") + time_min;
time_wr += "" + time_sec;
return time_wr;
}