Created
March 27, 2017 03:54
-
-
Save tristola/70c7ffb076c387fe96675b24e47d95b5 to your computer and use it in GitHub Desktop.
recursive function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RNFS from 'react-native-fs' | |
const getFolders = (dir) => { | |
return RNFS.readDir(dir).then( | |
result => result | |
.filter(item => item.isDirectory()) | |
.map(item => item.path) | |
) | |
} | |
async function getFoldersRecursive (dir, directories) { | |
const subfolders = await getFolders(dir) | |
return Promise.all(subfolders.map(folder => { | |
directories.push(folder) | |
return getFoldersRecursive(folder, directories) | |
})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment