-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolderRename.js
52 lines (44 loc) · 1.08 KB
/
folderRename.js
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
var fs = require('fs');
var path = require('path');
var ROOTPATH = '';
var directoryList = [];
var profile = {
'da': 'da_DK',
'de': 'de_DE',
'en': 'en_US',
'en-GB': 'en_GB',
'es': 'es_ES',
'fi': 'fi_FI',
'fr': 'fr_FR',
'fr-CA': 'fr_CA',
'it': 'it_IT',
'nl': 'nl_NL',
'no': 'nb_NO',
'pt-PT': 'pt_PT',
'ru': 'ru_RU',
'sv': 'sv_SE',
};
process.argv.forEach(function (val, index, array) {
if(index !== 2){ return false; }
ROOTPATH = val;
directoryList = getDirectories(ROOTPATH);
});
function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory()
});
}
var renameFolder = function(directories) {
for (var key in profile){
for(var i = 0; i < directories.length; ++i){
if(key === directories[i]){
var absPath = ROOTPATH + '/';
fs.rename(absPath + directories[i], absPath + profile[key]);
}
}
}
};
renameFolder(directoryList);
// find all directorys and store them in collection
// loop through a profile and match the directories to the profile
// directoryName: rename, path