123456789101112131415161718192021222324252627282930313233 |
- import fs from 'fs'
- import path from 'path'
- let read = 'dist/data'
- function deleteFile(url, name) {
- var files = []
- if (fs.existsSync(url)) {
-
- files = fs.readdirSync(url)
- files.forEach(function (file) {
- var curPath = path.join(url, file)
- if (fs.statSync(curPath).isDirectory()) {
-
- deleteFile(curPath, name)
- } else {
- if (file.indexOf(name) > -1) {
-
- fs.unlinkSync(curPath)
- console.log('删除文件:' + curPath)
- }
- }
- })
- } else {
- console.log('给定的路径不存在!')
- }
- }
- deleteFile(read, '.json')
|