* Remove file * Will delete contained folders and contained files * @param {String} _path - File to delete (start with `./`) * @returns {Boolean} File deleted or not
(_path = '')
| 291 | * @returns {Boolean} File deleted or not |
| 292 | */ |
| 293 | removeFile(_path = '') |
| 294 | { |
| 295 | // Errors |
| 296 | if(typeof _path !== 'string') |
| 297 | { |
| 298 | console.warn('removeFile: _path should be a string') |
| 299 | return false |
| 300 | } |
| 301 | |
| 302 | // Set up |
| 303 | const path = this.cleanPath(_path) |
| 304 | const pathParts = path.split('/') |
| 305 | const filePart = pathParts.pop() |
| 306 | |
| 307 | let folders = this.folders |
| 308 | let folder = null |
| 309 | |
| 310 | // Each path part |
| 311 | for(const _part of pathParts) |
| 312 | { |
| 313 | const index = folders.findIndex((folder) => _part === folder.name) |
| 314 | |
| 315 | // Found |
| 316 | if(index !== -1) |
| 317 | { |
| 318 | folder = folders[index] |
| 319 | folders = folder.folders |
| 320 | } |
| 321 | |
| 322 | // Not found |
| 323 | else |
| 324 | { |
| 325 | folder = null |
| 326 | folders = null |
| 327 | break |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // Folder found |
| 332 | if(folders && folder) |
| 333 | { |
| 334 | const index = folder.files.findIndex((file) => filePart === file.name) |
| 335 | |
| 336 | // File found |
| 337 | if(index !== -1) |
| 338 | { |
| 339 | const file = folder.files[index] |
| 340 | |
| 341 | // Delete |
| 342 | folder.files.splice(index, 1) |
| 343 | |
| 344 | // Auto wash |
| 345 | if(this.autoWash) |
| 346 | { |
| 347 | this.removeEmptyFolders() |
| 348 | } |
| 349 | |
| 350 | // Callback |
no test coverage detected