From 36def27516d6186427ee5dfc3a9d2c81a482d99c Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 13 Feb 2024 18:11:16 +1300 Subject: [PATCH] fix: ensure consistent file path formatting when reading directories recursively (#990) --- src/volume.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/volume.ts b/src/volume.ts index 332d82437..4f289b07c 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -1488,9 +1488,15 @@ export class Volume implements FsCallbackApi, FsSynchronousApi { if (options.withFileTypes) return list; + let filename2 = filename; + + if (isWin) { + filename2 = filename2.replace(/\\/g, '/'); + } + return list.map(dirent => { if (options.recursive) { - return dirent.path.replace(filename + pathModule.sep, ''); + return dirent.path.replace(filename2 + pathModule.posix.sep, ''); } return dirent.name; });