Last active
January 24, 2020 01:54
-
-
Save senthilmpro/54717f5b6653674a5318d785e7ec4fdc to your computer and use it in GitHub Desktop.
create-folder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const HOME_PATH = "/Users/senthilmpro/Desktop/test"; | |
const HOME_FOLDER = path.resolve(HOME_PATH); | |
const files = fs.readdirSync(HOME_FOLDER, 'utf-8'); | |
console.log(files); | |
const isMatch = (str) => { | |
let str1 = str.replace("."," ") | |
let regEx1 = new RegExp(/\w+ \(\d+\)/,"gi"); | |
let matches = str.match(regEx1); | |
if(matches && matches.length > 0){ | |
return matches[0]; | |
} | |
return null; | |
} | |
const createFolder = (str) => { | |
if(!fs.existsSync(str)){ | |
fs.mkdirSync(str); | |
} | |
} | |
console.log("HOME_FOLDER ", HOME_FOLDER); | |
files.forEach(v => { | |
const folderName = isMatch(v); | |
if(folderName){ | |
const fullPath = path.resolve(HOME_FOLDER, folderName); | |
console.log(fullPath); | |
createFolder(fullPath); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment