-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathGet Total File Size.jsx
More file actions
79 lines (66 loc) · 1.52 KB
/
Get Total File Size.jsx
File metadata and controls
79 lines (66 loc) · 1.52 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
/**
* Calculates total file size on disk of selected project items
*
* @author Zack Lovatt <zack@lova.tt>
* @version 0.1.1
*/
(function getTotalFileSize() {
var fileSizes = [
{
name: "kb",
size: 1024
},
{
name: "mb",
size: 1048576
},
{
name: "gb",
size: 1073741824
},
{
name: "tb", // why do you have assets this big?
size: 1099511627776
}
];
var items = app.project.selection;
if (items.length === 0) {
alert("Select some items!");
return;
}
var sum = getItemsSize(items);
var sizeCounter = 0;
var sizeDivisor = fileSizes[0];
while (
fileSizes[sizeCounter].size < sum &&
sizeCounter < fileSizes.length - 1
) {
sizeDivisor = fileSizes[sizeCounter];
sizeCounter++;
}
var outputSum = sum / sizeDivisor.size;
var output = "These items are " + outputSum.toFixed(2) + sizeDivisor.name;
alert(output, "Get Total File Size");
/**
* Gets the total file size on disk of selected project items
*
* @param {Item[]} items Items to get size of
* @return {number} Total size, in bytes
*/
function getItemsSize(items) {
var sum = 0;
for (var ii = 0, il = items.length; ii < il; ii++) {
var item = items[ii];
if (!(item instanceof FootageItem)) {
continue;
}
var source = item.mainSource;
if (!(source instanceof FileSource)) {
continue;
}
var fileSize = source.file.length;
sum += fileSize;
}
return sum;
}
})();