Organize files as they land

A file organizer starts sorting when you drop files. See how selection and execution can fit in one gesture.

TheDriveAI · File organization · Source post

Group dropped files by type

An independent web example inspired by the original reference.

Drop images or documents into the frame, or select files.

Implementation steps

  1. Provide a drop zone and a file picker button. On touch devices, the picker button offers the same action.
  2. Route both drop and file picker into one classification process, and list types and names.
  3. In your app, pass these classification results to storage destinations or tag suggestions. The sample shows selected results on-device.

Acceptance check

Dragging and selecting produce the same classification. Files with unrecognized formats remain under “Other.”

View sample code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Group dropped files by type</title>
<style>
  * { box-sizing: border-box; }
  body {
    margin: 0;
    padding: 16px;
    background: #23232a;
    color: #f4f0ea;
    font: 16px/1.6 system-ui, sans-serif;
  }
  label, output, strong, audio, progress { display: block; margin: 6px 0; }
  input, select, button { max-width: 100%; font: inherit; }
  input, select { padding: 4px 7px; }
  button {
    margin: 4px 0;
    padding: 5px 12px;
    cursor: pointer;
    border: 1px solid #b5a399;
    border-radius: 6px;
  }
  :focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
  audio { width: 100%; }
  [hidden] { display: none !important; }
#drop { border: 2px dashed #a39289; border-radius: 12px; padding: 20px; }
#drop.over { background: #514035; }
</style>
</head>
<body>
<label id="drop">Drop files here or choose files
  <input type="file" id="pick" multiple>
</label>
<ul id="files" aria-live="polite"></ul>
<script>
const drop = document.querySelector('#drop');
function list(files) {
  const groups = new Map();
  for (const file of files) {
    const type = file.type.split('/')[0] || 'Other';
    if (!groups.has(type)) groups.set(type, []);
    groups.get(type).push(file.name);
  }
  const list = document.querySelector('#files');
  list.replaceChildren();
  for (const [type, names] of groups) {
    const row = document.createElement('li');
    row.textContent = type + ': ' + names.join(', ');
    list.append(row);
  }
}
drop.ondragover = event => { event.preventDefault(); drop.classList.add('over'); };
drop.ondragleave = () => drop.classList.remove('over');
drop.ondrop = event => {
  event.preventDefault();
  drop.classList.remove('over');
  list(event.dataTransfer.files);
};
document.querySelector('#pick').onchange = event => list(event.target.files);
</script>
</body>
</html>

Save as index.html and open in a browser to run it locally.

Compare visual changes on your screenAll patterns