mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
64d71d6920
fixes #12
21 lines
715 B
TypeScript
21 lines
715 B
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
export const copyDirectory = async (
|
|
source: string,
|
|
destination: string
|
|
): Promise<void> => {
|
|
const filesToCreate = await fs.promises.readdir(source)
|
|
for (const file of filesToCreate) {
|
|
const originalFilePath = path.join(source, file)
|
|
const stats = await fs.promises.stat(originalFilePath)
|
|
if (stats.isFile()) {
|
|
const writePath = path.join(destination, file)
|
|
await fs.promises.copyFile(originalFilePath, writePath)
|
|
} else if (stats.isDirectory()) {
|
|
await fs.promises.mkdir(path.join(destination, file), { recursive: true })
|
|
await copyDirectory(path.join(source, file), path.join(destination, file))
|
|
}
|
|
}
|
|
}
|