-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbackupModificationTimesOfMusic
executable file
·65 lines (54 loc) · 2.02 KB
/
backupModificationTimesOfMusic
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
#!/bin/bash
find . -iname "*.mp3*" -o -iname "*.flac*" -o -iname "*.aif*" -o -iname "*.wav*" -o -iname "*.mp4*" -o -iname "*.ogg*" | while read filename;
do
IFS=$'\n' printf "\ntouch -t $(stat -f "%Sm" -t "%Y%m%d%H%M" "$filename") \"$filename\"";
#printf "\ntouch -t \"$filename\"";
done;
printf "\n";
Object.defineProperty(Date.prototype, 'YYYYMMDDHHMMSS', {
value: function() {
function pad2(n) { // always returns a string
return (n < 10 ? '0' : '') + n;
}
return this.getFullYear() +
pad2(this.getMonth() + 1) +
pad2(this.getDate()) +
pad2(this.getHours()) +
pad2(this.getMinutes()) +
pad2(this.getSeconds());
}
});
var path="/Users/thomash/";
var filePath=path+"modifiedDateBackup"
# fs.writeFile(filePath,"");
var fs=require("fs");
var s="";
filewalker(path).on("file",(filename,info) => {
if (
filename.toLowerCase().endsWith(".mp3") ||
filename.toLowerCase().endsWith(".wav") ||
filename.toLowerCase().endsWith(".aif") ||
filename.toLowerCase().endsWith(".flac")||
filename.toLowerCase().endsWith(".aiff") ||
filename.toLowerCase().endsWith(".mp4")) {
var date = new Date(info.mtime).YYYYMMDDHHMMSS();
s += date+" "+filename+"\n";
}
}).on("error", e=>console.error("error",e)).on("done",()=> fs.writeFileSync(filePath,s)).walk();
var s = fs.readFileSync(filePath).toString();
s.split("\n").forEach(line => {
var spit=line.split(" ");
var date = spit.shift();
var file = spit.join(" ");
if (line.trim().length === 0)
return;
var formattedDate = new Date(date[0]+date[1]+date[2]+date[3]+" "+date[4]+date[5]+" "+date[6]+date[7]+" "+date[8]+date[9]+":"+date[10]+date[11]);
console.log("datefile",{date,file,formattedDate});
try {
console.log("line",line);
console.log("modifying ",path+file, formattedDate);
fs.utimesSync(path+file, formattedDate, formattedDate);
} catch (e) {
console.error("err",e);
}
})