Skip to content

Commit

Permalink
feat: add a new method listSasFilesInFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
sabhas committed Jan 4, 2023
1 parent a833a53 commit 8f6875c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/file/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ export async function listIniFilesInFolder(folderName: string) {
)
}

export async function listSasFilesInFolder(
folderName: string,
recurse: boolean = false,
ignoredFolders: string[] = []
) {
const filesAndFolders = await listFilesAndSubFoldersInFolder(
folderName,
recurse,
ignoredFolders
)
const sasFiles = filesAndFolders.filter((f) => f.endsWith('.sas'))
return sasFiles
}

export async function listSubFoldersInFolder(
folderName: string
): Promise<string[]> {
Expand All @@ -58,7 +72,8 @@ export async function listSubFoldersInFolder(

export async function listFilesAndSubFoldersInFolder(
folderName: string,
recurse: boolean = true
recurse: boolean = true,
ignoredFolders: string[] = []
): Promise<string[]> {
return fs.promises
.readdir(folderName, { withFileTypes: true })
Expand All @@ -73,14 +88,16 @@ export async function listFilesAndSubFoldersInFolder(
list.filter((f) => f.isDirectory()),
async (f) => {
const subFolder = f.name
const subPath = path.join(folderName, subFolder)

subFoldersFilesAndFolders = [
...subFoldersFilesAndFolders,
...(await listFilesAndSubFoldersInFolder(subPath)).map((f) =>
path.join(subFolder, f)
)
]
if (!ignoredFolders.includes(subFolder)) {
const subPath = path.join(folderName, subFolder)

subFoldersFilesAndFolders = [
...subFoldersFilesAndFolders,
...(await listFilesAndSubFoldersInFolder(subPath)).map((f) =>
path.join(subFolder, f)
)
]
}
}
)

Expand Down
1 change: 1 addition & 0 deletions src/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
readFileBinary,
listFilesInFolder,
listIniFilesInFolder,
listSasFilesInFolder,
listSubFoldersInFolder,
listFilesAndSubFoldersInFolder,
createFile,
Expand Down

0 comments on commit 8f6875c

Please sign in to comment.