Created
March 28, 2023 10:00
-
-
Save FishingHacks/3721fd2a8b6cedc188bbdef31187ba2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { join } from 'path'; | |
import './globals'; | |
export async function fileExplorer(dir: string) { | |
while (true) { | |
if (!(await fs.isDir(dir))) break; | |
const entries = await fs.listDir(dir); | |
entries.unshift('..'); | |
const choice = await arg( | |
dir.startsWith(getHomePath()) | |
? dir.replace(getHomePath(), '~') | |
: dir, | |
entries | |
); | |
dir = join(dir, choice); | |
} | |
return dir; | |
} | |
export async function dirExplorer(dir: string) { | |
while (true) { | |
const _entries = await fs.listDir(dir); | |
const entries: string[] = []; | |
for (const f of _entries) if (await fs.isDir(join(dir, f))) entries.push(f); | |
entries.unshift('..'); | |
entries.unshift('\\select this directory/'); | |
const choice = await arg( | |
dir.startsWith(getHomePath()) | |
? dir.replace(getHomePath(), '~') | |
: dir, | |
entries | |
); | |
if (choice === '\\select this directory/') return dir; | |
dir = join(dir, choice); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment