File
对象
¥File
Object
使用 HTML5
File
API 原生处理文件系统上的文件。¥Use the HTML5
File
API to work natively with files on the filesystem.
警告 Electron 添加到
File
接口的path
属性已被弃用,并将在未来的 Electron 版本中删除。我们建议你改用webUtils.getPathForFile
。¥The
path
property that Electron adds to theFile
interface is deprecated and will be removed in a future Electron release. We recommend you usewebUtils.getPathForFile
instead.
DOM 的文件接口提供了对原生文件的抽象,以便让用户可以直接使用 HTML5 文件 API 处理原生文件。Electron 在 File
接口中添加了 path
属性,该属性公开了文件系统上文件的真实路径。
¥The DOM's File interface provides abstraction around native files in order to
let users work on native files directly with the HTML5 file API. Electron has
added a path
attribute to the File
interface which exposes the file's real
path on filesystem.
从拖到应用文件中获取真实路径的示例:
¥Example of getting a real path from a dragged-onto-the-app file:
<div id="holder">
Drag your file here
</div>
<script>
document.addEventListener('drop', (e) => {
e.preventDefault();
e.stopPropagation();
for (const f of e.dataTransfer.files) {
console.log('File(s) you dragged here: ', f.path)
}
});
document.addEventListener('dragover', (e) => {
e.preventDefault();
e.stopPropagation();
});
</script>