当前位置: 首页 > news >正文

How to use js open a specific folder in the browser All In One

How to use js open a specific folder in the browser All In One

Window showDirectoryPicker

image

demos

// open-a-specific-folder.jsdocument.addEventListener("DOMContentLoaded", (event) => {console.log("DOM fully loaded and parsed ✅");const btnDesktop = document.querySelector(`#btn_desktop`);const btnDownload = document.querySelector(`#btn_download`);const btnDocument = document.querySelector(`#btn_document`);//btnDesktop.addEventListener(`click`, async (e) => {try {const dirHandle = await window.showDirectoryPicker({id: 'desktop-picker',mode: "readwrite",startIn: 'desktop',// ✅});console.log(`dirHandle =`, dirHandle);for await (const [name, handle] of dirHandle) {console.log(`${name} - ${handle.kind}`);}} catch (err) {console.error(`❌ Error selecting directory:`, err);}});btnDownload.addEventListener(`click`, async (e) => {try {const dirHandle = await window.showDirectoryPicker({id: 'download-picker',mode: "readwrite",startIn: 'downloads',// ✅});console.log(`dirHandle =`, dirHandle);for await (const [name, handle] of dirHandle) {console.log(`${name} - ${handle.kind}`);}} catch (err) {console.error(`❌ Error selecting directory:`, err);}});btnDocument.addEventListener(`click`, async (e) => {try {const dirHandle = await window.showDirectoryPicker({id: 'document-picker',mode: "readwrite",// startIn: 'documents',// ✅// startIn: 'music',// ✅// startIn: 'pictures',// ✅startIn: 'videos',// ✅ in macOS videos === movies ⚠️// startIn: 'movies',// ❌// startIn: 'documents/github',// installHook.js:1 ❌ Error selecting directory: TypeError: Failed to execute 'showDirectoryPicker' on 'Window': Failed to read the 'startIn' property from 'DirectoryPickerOptions': The provided value 'documents/github' is not a valid enum value of type WellKnownDirectory.// startIn: 'applications',// ❌// startIn: 'airdrop',// ❌// startIn: 'library',// ❌// startIn: 'share',// ❌});console.log(`dirHandle =`, dirHandle);for await (const [name, handle] of dirHandle) {console.log(`${name} - ${handle.kind}`);}} catch (err) {console.error(`❌ Error selecting directory:`, err);}});
});/*https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPickerstartIn Optional
A FileSystemHandle or a well known directory ("desktop", "documents", "downloads", "music", "pictures", or "videos") to open the dialog in.*/

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPicker



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


http://www.jsqmd.com/news/162119/

相关文章:

  • 早上八点的电费涨到一块二了,家里的洗衣机还在嗡嗡转。我瘫在沙发上刷着电费账单,突然意识到这年头连用个电都得玩策略游戏——分时电价这玩意儿简直比股票K线图还刺激
  • git diff比较代码差异:追踪PyTorch-CUDA-v2.8配置变更
  • 吴恩达深度学习课程四:计算机视觉 第四周:卷积网络应用 (一) 人脸识别
  • 大数据领域数据生命周期,藏在细节里的宝藏
  • 最近在研究磁耦合谐振式无线电能传输,发现相控电容式补偿方法挺有意思的。今天就来聊聊这个,顺便用Simulink仿真一下,看看效果如何
  • Hyperchain的智能合约
  • YOLOv5/YOLOv11模型训练提速秘籍:PyTorch-CUDA-v2.8镜像实战
  • 不用再git clone了!PyTorch-CUDA镜像内置完整开发套件
  • PyTorch安装包下载慢?国内加速镜像站点推荐列表
  • Spring 高性能多级缓存全攻略:Caffeine + Redis 生产级实践
  • 【计算机毕业设计案例】基于springboot的骑行运动爱好者社交骑行交流论坛的设计与开发(程序+文档+讲解+定制)
  • HuggingFace镜像网站加载慢?本地PyTorch-CUDA环境来救场
  • 文件管理
  • 【毕业设计】基于springboot的骑行交流论坛的设计与开发(源码+文档+远程调试,全bao定制等)
  • 牛拉法电力系统潮流计算 MATLAB编写潮流计算程序 BPA计算潮流 另外包含参考文献
  • 如何自定义扩展PyTorch-CUDA镜像?Dockerfile编写教程
  • diskinfo检测NVMe缓存:优化PyTorch-CUDA-v2.8数据读取速度
  • 共识机制RBFT的具体流程
  • 20kw光伏逆变器 20KW双路光伏BOOST三相三电平光伏并网逆变器 带两路boost追踪M...
  • YOLOv5训练卡顿?升级到PyTorch-CUDA-v2.8显著提速
  • 华为云国际站代理商WeLink的资源与工具支持具体有哪些?
  • github organization管理团队项目:协作开发PyTorch-CUDA-v2.8
  • ssh批量管理多台机器:统一运维PyTorch-CUDA-v2.8集群
  • 华为云国际站代理商EDCM主要有什么作用呢?
  • anaconda配置pytorch环境耗时太久?建议切换至容器化方案
  • 如何快速配置PyTorch-GPU环境?PyTorch-CUDA-v2.8镜像使用指南
  • Hyperchain中区块打包的实现
  • PyTorch-CUDA镜像推荐:高效运行CNN、YOLOv5和HuggingFace模型
  • GitHub项目本地复现难?PyTorch-CUDA镜像帮你搞定依赖
  • PyTorch-CUDA环境 vs 传统Anaconda:谁更适合深度学习?