Created
January 7, 2021 02:50
-
-
Save iamspark1e/f62d4bd37a18a916770fca25d52deb5d to your computer and use it in GitHub Desktop.
Make a folder named by today, start your work by this!
This file contains 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"); | |
function autoFillZero(str) { | |
return parseInt(str) < 10 ? "0" + str : str; | |
} | |
function generateFolderName() { | |
const today = new Date(); | |
return `${today.getFullYear()}-${autoFillZero(today.getMonth() + 1)}-${autoFillZero(today.getDate())}` | |
} | |
/* | |
* @function main | |
* @argv [2]-path The daily create path, can be configured in Schedule. | |
*/ | |
function main() { | |
const argv = process.argv; | |
const folder = generateFolderName(); | |
const todayFolderName = argv[2] + "/" + folder; | |
if(fs.existsSync(todayFolderName)) { | |
// console.log(`${todayFolderName} 今天的工作文件夹创建成功,开始工作吧!`); | |
// process.exit(0); | |
return; | |
} else { | |
fs.mkdirSync(todayFolderName); | |
if(fs.existsSync(todayFolderName)) { | |
console.log(`${todayFolderName} 今天的工作文件夹创建成功,开始工作吧!`) | |
// process.exit(0); | |
return; | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment