mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: use for loop in fs operations
This commit is contained in:
parent
282b69f4a3
commit
30202bac79
@ -48,22 +48,19 @@ export async function moveFiles(
|
|||||||
const files = await fs.promises.readdir(sourceFolder);
|
const files = await fs.promises.readdir(sourceFolder);
|
||||||
|
|
||||||
// Filter only files (skip directories)
|
// Filter only files (skip directories)
|
||||||
const filePaths = await Promise.all(
|
const filePaths = [];
|
||||||
files.map(async (file) => {
|
for (const file of files) {
|
||||||
const filePath = join(sourceFolder, file);
|
const filePath = join(sourceFolder, file);
|
||||||
const stat = await fs.promises.stat(filePath);
|
const stat = await fs.promises.stat(filePath);
|
||||||
return stat.isFile() ? filePath : null;
|
if (stat.isFile()) {
|
||||||
}),
|
filePaths.push(filePath);
|
||||||
);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Move each file to the destination folder
|
// Move each file to the destination folder
|
||||||
const movePromises = filePaths
|
for (const filePath of filePaths) {
|
||||||
.filter((filePath): filePath is string => filePath !== null)
|
const fileName = basename(filePath);
|
||||||
.map((filePath) => {
|
const destination = resolve(join(destinationFolder, fileName));
|
||||||
const fileName = basename(filePath);
|
await moveFile(filePath, destination, overwrite);
|
||||||
const destination = resolve(join(destinationFolder, fileName));
|
}
|
||||||
return moveFile(filePath, destination, overwrite);
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(movePromises);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user