選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ensureFile.md 672 B

1234567891011121314151617181920212223242526272829
  1. # ensureFile(file, [callback])
  2. Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.
  3. **Alias:** `createFile()`
  4. - `file` `<String>`
  5. - `callback` `<Function>`
  6. ## Example:
  7. ```js
  8. const fs = require('fs-extra')
  9. const file = '/tmp/this/path/does/not/exist/file.txt'
  10. fs.ensureFile(file, err => {
  11. console.log(err) // => null
  12. // file has now been created, including the directory it is to be placed in
  13. })
  14. // With Promises:
  15. fs.ensureFile(file)
  16. .then(() => {
  17. console.log('success!')
  18. })
  19. .catch(err => {
  20. console.error(err)
  21. })
  22. ```