diff options
| author | Priyansh <[email protected]> | 2020-12-23 20:10:17 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2020-12-23 20:10:17 +0530 |
| commit | b18cf71249b26d965215bcf06204daf6af5f55e7 (patch) | |
| tree | c077bb09d95bb17e7cd9e863cfa793374d2e42a4 /src | |
| parent | ad76cf4c73488ba871261959c2907fc7623a1460 (diff) | |
| download | styx-b18cf71249b26d965215bcf06204daf6af5f55e7.tar.xz styx-b18cf71249b26d965215bcf06204daf6af5f55e7.zip | |
Getting all files and folders of home directory
Diffstat (limited to 'src')
| -rw-r--r-- | src/renderer.ts | 18 | ||||
| -rw-r--r-- | src/systemLevelInformation.ts | 33 |
2 files changed, 45 insertions, 6 deletions
diff --git a/src/renderer.ts b/src/renderer.ts index 66042ac..d3a21bc 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -1,6 +1,12 @@ -// This file is required by the app.html file and will -// be executed in the renderer process for that window. -// No Node.js APIs are available in this process unless -// nodeIntegration is set to true in webPreferences. -// Use preload.js to selectively enable features -// needed in the renderer process. +import systemLevelInformation from './systemLevelInformation'; + +// Listing Files in Home Directory + +const currentHomeDir: string = systemLevelInformation.getUserInfo().homedir; +document.getElementById('username').innerHTML = systemLevelInformation.getUserInfo().username; + +// This variable will keep track of current path +var currentDirectoryPath: string = currentHomeDir; + +const currentHomeFolders: any = systemLevelInformation.getAllFilesOfDirectory(currentHomeDir); + diff --git a/src/systemLevelInformation.ts b/src/systemLevelInformation.ts new file mode 100644 index 0000000..e902d32 --- /dev/null +++ b/src/systemLevelInformation.ts @@ -0,0 +1,33 @@ +import * as os from 'os'; +import * as glob from 'glob'; +import { statSync, readdirSync } from 'fs'; +import { extname, basename } from 'path'; + +class systemLevelInformation { + + getUserInfo(): { username: string, homedir: string } { + return { + username: os.userInfo().username, + homedir: os.userInfo().homedir + }; + } + + getAllFilesOfDirectory(currentDirectory): { files: string[], directories: string[] } { + const currentFilteredItems: string[] = readdirSync(currentDirectory).filter((item: string) => item.indexOf(".") !== 0); + const files: string[] = []; + const directories: string[] = []; + + currentFilteredItems.forEach((item: string) => { + if (statSync(`${currentDirectory}/${item}`).isDirectory()) { + directories.push(item); + } else { + files.push(item); + } + }); + + return { files, directories }; + } + +} + +export default new systemLevelInformation; |
