Electron 无法在 windows 10 上写入文件
Electron can't write files on windows 10
使用 fs-extra 写入文件在 windows 10 上失败。outputFile method 应该在写入之前创建任何丢失的目录,但它会引发错误。不过,我知道下载目录已经存在。
Error: ENOENT: no such file or directory, open 'C:\Users\josh\Downloads18-01-13_15:14:11.png'
const fs = require('fs-extra')
const app = require('electron').remote.app
const moment = require('moment')
let dataURL = this.$.canvas.toDataURL()
let filename = moment().format('YYYY-MM-DD_HH:mm:ss') + '.png'
let buffer = new Buffer(dataURL.replace('data:image/png;base64', ''), 'base64')
let filepath = path.resolve(app.getPath('downloads'), filename)
fs.outputFile(filepath, buffer, err => {
if (err) {
console.error(err)
}
})
您不能在 Windows.
的文件名中使用冒号“:”
来自Naming Files, Paths, and Namespaces:
Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
The following reserved characters:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
- Integer value zero, sometimes referred to as the ASCII NUL character.
- Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
- Any other character that the target file system does not allow.
使用 fs-extra 写入文件在 windows 10 上失败。outputFile method 应该在写入之前创建任何丢失的目录,但它会引发错误。不过,我知道下载目录已经存在。
Error: ENOENT: no such file or directory, open 'C:\Users\josh\Downloads18-01-13_15:14:11.png'
const fs = require('fs-extra')
const app = require('electron').remote.app
const moment = require('moment')
let dataURL = this.$.canvas.toDataURL()
let filename = moment().format('YYYY-MM-DD_HH:mm:ss') + '.png'
let buffer = new Buffer(dataURL.replace('data:image/png;base64', ''), 'base64')
let filepath = path.resolve(app.getPath('downloads'), filename)
fs.outputFile(filepath, buffer, err => {
if (err) {
console.error(err)
}
})
您不能在 Windows.
的文件名中使用冒号“:”来自Naming Files, Paths, and Namespaces:
Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
The following reserved characters:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
- Integer value zero, sometimes referred to as the ASCII NUL character.
- Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
- Any other character that the target file system does not allow.