LoginSignup
80
65

More than 5 years have passed since last update.

ElectronでOS固有のファイルパスを得る app.getPath()の出力まとめ

Last updated at Posted at 2015-11-14

ドキュメントにはふわっとしか載っていなかったのでここにまとめます。
https://github.com/atom/electron/blob/master/docs/api/app.md#appgetpathname

Electron v0.34.3

Windows

index.js
console.log(app.getPath('home'));      // -> C:\Users\【ユーザー名】
console.log(app.getPath('appData'));   // -> C:\Users\【ユーザー名】\AppData\Roaming
console.log(app.getPath('userData'));  // -> C:\Users\【ユーザー名】\AppData\Roaming\【パッケージ名】
console.log(app.getPath('temp'));      // -> C:\Users\【ユーザー名】\AppData\Local\Temp
console.log(app.getPath('exe'));       // -> 【実行している.exeのパス】
console.log(app.getPath('module'));    // -> 【実行している.exeのパス】
console.log(app.getPath('desktop'));   // -> エラー
console.log(app.getPath('documents')); // -> エラー
console.log(app.getPath('downloads')); // -> エラー
console.log(app.getPath('music'));     // -> エラー
console.log(app.getPath('pictures'));  // -> エラー
console.log(app.getPath('videos'));    // -> エラー

Mac

index.js
console.log(app.getPath('home'));      // -> /Users/【ユーザー名】
console.log(app.getPath('appData'));   // -> /Users/【ユーザー名】/Library/Application Support
console.log(app.getPath('userData'));  // -> /Users/【ユーザー名】/Library/Application Support/【パッケージ名】
console.log(app.getPath('temp'));      // -> /var/folders/df/w01nd66568g0ql8wdmcd21vr0000gn/T/
console.log(app.getPath('exe'));       // -> 【実行している.appのパス】/Contents/MacOS/Electron
console.log(app.getPath('module'));    // -> 【実行している.appのパス】/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework
console.log(app.getPath('desktop'));   // -> エラー
console.log(app.getPath('documents')); // -> エラー
console.log(app.getPath('downloads')); // -> エラー
console.log(app.getPath('music'));     // -> エラー
console.log(app.getPath('pictures'));  // -> エラー
console.log(app.getPath('videos'));    // -> エラー

...何故かdesktop以下はエラーに。

80
65
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
80
65