Reputation: 167706
Chrome version 132 has introduced the file system access API with a directory picker https://developer.chrome.com/docs/capabilities/web-apis/file-system-access.
However, while on desktop versions of Chrome, the ˋresolveˋ function of a directory entry returns a Promise with an array of path components to an entry https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve, under Android it appears that function returns always, independent of the nesting level, only a two component path starting with ˋdocumentˋ followed by a string that has directories included but separated by ˋ%2ˋ and a prefix of e.g. ˋprimary%3ADocuments%2Fˋ.
Is that difference between Chrome desktop ˋresolveˋ and Android ˋresolveˋ by design or a quirk/bug of that first release?
A sample page opening a directory picker is https://martin-honnen.github.io/js/2025/directoryPickerTest1.html, if I open a directory e.g. named ˋxslt-1.0ˋ on a desktop version of Chrome I get some hierarchy of e.g.
While on Android I get flat paths in the forms of e.g.
I also include the code as a code snippet but as the JavaScript is executed in there inside of an iframe the use of a directory picker does not work.
async function buildRootDirList(dirHandle) {
const ul = document.createElement('ul');
document.body.appendChild(ul);
const li = document.createElement('li');
ul.appendChild(li);
li.appendChild(document.createTextNode(dirHandle.name));
await buildDirList(dirHandle, dirHandle, li);
}
async function buildDirList(dirHandle, rootDirHandle, parentElement) {
const ul = document.createElement('ul');
parentElement.appendChild(ul);
for await (const entry of dirHandle.values()) {
const li = document.createElement('li');
ul.appendChild(li);
li.appendChild(document.createTextNode(`${entry.name} (${(await rootDirHandle.resolve(entry)).join('/')})`));
if (entry.kind === 'directory') {
await buildDirList(entry, rootDirHandle, li);
}
}
}
document.getElementById('dp1').addEventListener('click', async () => {
const dirHandle = await window.showDirectoryPicker();
await buildRootDirList(dirHandle);
});
<input type=button id=dp1 value=test>
Upvotes: -1
Views: 116
Reputation: 15
The reason you're not seeing distinct path components returned from the resolve method of the FileSystemDirectoryHandle in Chrome for Android is because Android uses content URIs for paths, which are opaque identifiers. These content URIs don't follow the typical hierarchical file path structure with separators like /dir/subdir/file.txt. Instead, they are represented as something like content://authority/path1.
This difference in path representation means that the resolve method doesn't return the expected array of directory names1.
Upvotes: 1