* Remove folder * Will delete contained folders and contained files * @param {String} _path - Folder to delete (start with `./`) * @returns {Boolean} Folder deleted or not
(_path = '')
| 182 | * @returns {Boolean} Folder deleted or not |
| 183 | */ |
| 184 | removeFolder(_path = '') |
| 185 | { |
| 186 | // Recursive emptying |
| 187 | const emptyFolder = function(folder) |
| 188 | { |
| 189 | // Delete folders |
| 190 | for(const _folderKey in folder.folders) |
| 191 | { |
| 192 | const _folder = folder.folders[_folderKey] |
| 193 | |
| 194 | emptyFolder(_folder) |
| 195 | |
| 196 | folder.folders.splice(_folderKey, 1) |
| 197 | |
| 198 | // Callback |
| 199 | if(typeof _folder.onRemove === 'function') |
| 200 | { |
| 201 | _folder.onRemove.apply(this, [_folder]) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Delete files |
| 206 | for(const _fileKey in folder.files) |
| 207 | { |
| 208 | const _file = folder.files[_fileKey] |
| 209 | |
| 210 | folder.files.splice(_fileKey, 1) |
| 211 | |
| 212 | // Callback |
| 213 | if(typeof _file.onRemove === 'function') |
| 214 | { |
| 215 | _file.onRemove.apply(this, [_file]) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // Errors |
| 221 | if(typeof _path !== 'string') |
| 222 | { |
| 223 | console.warn('removeFolder: _path should be a string') |
| 224 | return false |
| 225 | } |
| 226 | |
| 227 | // Set up |
| 228 | const path = this.cleanPath(_path) |
| 229 | const pathParts = path.split('/') |
| 230 | const folderPart = pathParts.pop() |
| 231 | |
| 232 | let folders = this.folders |
| 233 | let folder = null |
| 234 | |
| 235 | // Each path part |
| 236 | for(const _part of pathParts) |
| 237 | { |
| 238 | const index = folders.findIndex((folder) => _part === folder.name) |
| 239 | |
| 240 | // Found |
| 241 | if(index !== -1) |
nothing calls this directly
no test coverage detected