test
fftfantt edited this page Jul 11, 2016
·
3 revisions
(function() {
'use strict';
// プロジェクトディレクトリー
DataManager.databaseDirectoryPath = function() {
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "");
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
//拡張子除外
function excludExtension(files){
for (var i=0 ; i< files.length ; i++){
files[i]= '"' + files[i].match(/(.*)(?:\.([^.]+$))/)[1] + '"';
}
return files;
};
//ファイルリスト
function outFileList(kind,dir) {
//console.log('outFileList')
fs.readdir(dir, function(err, files) {
if (err) return;
files = excludExtension(files);
//if (strJSON ==undefined) strJSON = ''
strJSON = strJSON + '"' + kind + '"' + ':[' + files + '],'
})
};
//フォルダリスト
function outDirList(dir){
//console.log('outDirList')
fs.readdir(dir, function(err, files){
if (err) return;
files.forEach(function(file) {
if(fs.statSync( dir + file + '/').isDirectory());
outFileList( file ,dir + file + '/');
});
});
};
//メイン処理
var dir = DataManager.databaseDirectoryPath();
var fs = require('fs');
var strJSON = '';
outDirList(dir + '/audio/');
outDirList(dir + '/img/');
setTimeout(function() {
outFileList('/moves/' , dir + '/moves/');
strJSON = '{' + strJSON.substr( 0, strJSON.length-1 ) + '}'
fs.writeFileSync(dir + '/data/MV_Project.json', strJSON);
},1000)
})();