File size: 424 Bytes
b2d7d99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { promises as fs } from "node:fs"
import path from "node:path"

export const deleteFilesWithName = async (dir: string, name: string) => {
  for (const file of await fs.readdir(dir)) {
    if (file.includes(name)) {
      const filePath = path.join(dir, file)
      try {
        await fs.unlink(filePath)
      } catch (err) {
        console.error(`failed to unlink file in ${filePath}: ${err}`)
      }
    }
  }
}