1
0
Fork 0
mirror of https://github.com/em-squared/5e-drs.git synced 2025-10-30 05:04:21 +00:00
This commit is contained in:
Maxime Moraine 2020-04-11 10:39:54 +02:00
parent 0c6b3ded94
commit 210a86b6c4
3204 changed files with 12805 additions and 12712 deletions

35
import/directorize.js Normal file
View file

@ -0,0 +1,35 @@
const path = require('path')
const fs = require('fs')
const directoryPath = path.join(__dirname, 'liste-objets-magiques')
fs.readdir(directoryPath, function (err, files) {
// Gestion d'erreur
if (err) {
return console.log('Unable to scan directory: ' + err)
}
// Traitement des fichiers
files.forEach(function (file) {
// On ignore les répertoires
let filePath = directoryPath+'/'+file
if (fs.lstatSync(filePath).isFile()) {
console.log(file)
let dirName = file.substring(0, file.length-3)
console.log(dirName)
fs.readFile(filePath, {encoding:'utf-8'}, (err, filecontent) => {
if (err) throw err
fs.mkdir(directoryPath+'/'+dirName, (err) => {
if (err) throw err
fs.writeFile(directoryPath + '/' + dirName + '/' + "README.md", filecontent, function(err) {
if(err) {
return console.log(err);
}
console.log("Saved: " + directoryPath + '/' + dirName + '/' + "README.md")
fs.unlink(filePath, (err) => {
if (err) throw err
})
})
})
})
}
})
})