[directory-upload] easier way to determine if something is a directory? (#24)

I see in the examples that you do:

```js
filesAndDirs[i].getFilesAndDirectories === 'function'
```
This seems like a heavy handed way of filtering on "is a directory", no? 

Basically, what I would want to do is:

```JS
ev.dataTransfer.getFilesAndDirectories()
  .then(fileOrDirs => items.map(
    fileOrDir => (fileOrDir.isDirectory) ? fileOrDir.getFilesAndDirectories() : Promise.resolve(fileOrDir)  
  ))
  .then(filePromises => Promise.all(filePromises))
  .then(uploadFiles)
  .catch(err);
```

Or (I haven't actually tried this, but you get the idea hopefully):

```JS
async function handleDrop(e){
  e.stopPropagation();
  e.preventDefault();
  // Not supported, so bail out?
  if (!('getFilesAndDirectories' in e.dataTransfer)){
      return;
  }
  let fileOrDirs = ev.dataTransfer.getFilesAndDirectories();
  let files = fileOrDirs.reduce((collection, next) => {
    let files = [];
    try{
      files = (item.isDirectory) ? await fileOrDir.getFilesAndDirectories() : [file];
    } catch (err){
      //do something useful, maybe 
    }
    collection.concat(files);
    return collection;
  });
 //finally
 upload(files);
}
```

---
Reply to this email directly or view it on GitHub:
https://github.com/WICG/directory-upload/issues/24

Received on Tuesday, 1 December 2015 07:44:34 UTC