diff --git a/src/index.ts b/src/index.ts index 3d9460ea..de3eb0c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,8 +92,7 @@ const run = async (config: R2Config) => { console.log(file); console.log(config.sourceDir); console.log(config.destinationDir); - //const fileName = file.replace(/^.*[\\\/]/, ""); - const fileName = path.basename(file); + const fileName = file.replace(config.sourceDir, ""); const fileKey = path.join(config.destinationDir !== "" ? config.destinationDir : config.sourceDir, fileName); if (fileKey.includes('.gitkeep')) diff --git a/src/utils.ts b/src/utils.ts index 2c6fe599..4a9fe47c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,5 @@ import fs from 'fs'; +import path from 'path'; export const formatBytes = function (bytes: number): string { const sizes = ["Bytes", "KB", "MB", "GB", "TB"] @@ -30,7 +31,7 @@ export const getFileList = (dir: string) => { for (const item of items) { const isDir = item.isDirectory(); - const absolutePath = `${dir}/${item.name}`; + const absolutePath = path.join(dir, item.name); if (isDir) { files = [...files, ...getFileList(absolutePath)]; } else {