Logo

dev-resources.site

for different kinds of informations.

Quick Tip: findFile

Published at
11/21/2023
Categories
miniscript
minimicro
programming
tip
Author
joestrout
Author
9 person written this
joestrout
open
Quick Tip: findFile

Mini Micro version 1.2 includes a new global function, findFile, which is really handy. If you're not already using it, you're missing out! And if you are already enjoying it, skim to the end, where you may learn something about it you didn't already know.

Screen shot of findFile

If you just type findFile at the prompt, it pops up a three-column file dialog as shown above. You can use the arrow keys to navigate anywhere in the file hierarchy, including the user disks (/usr and /usr2, if mounted) as well as the system disk (/sys).

The leftmost column shows the directory you're currently in, along with its context (any files or volumes at the same level). The center column lists all the files and subdirectories thereof. And the column on the right shows a preview of the file, whenever possible:

  • MiniScript source files show the first dozen lines or so of the code. You only get to see about 14 characters of each line, but this is often enough to be sure you've got the right script, or check the imports or constants at the top of the file.

  • Text files (ending in .txt, .grfon, .json, etc.) similarly show the first part of the first dozen lines or so.

  • Images show the actual picture (as in the screen shot above). These are scaled up or down as necessary to fit.

  • Sounds show the sound duration, but more importantly, the sound is actually played when selected! To play it again, just switch to another file and back.

When you've found the file you want, click the Select button, or just press Return/Enter. The dialog will disappear, and the path to the selected file will be returned.

Screen shot showing return value of a findFile call

You can then select and copy that path from the text display, edit your program, and paste it into your code. Or, when tinkering around on the command line, you can use this directly anywhere you need a file path. For example:

Screen shot showing loading of fish sprite via findFile

Note the use of findFile in the second line!

You can also use findFile when you don't actually care about the return value, but you just want to explore. It's a great way to poke around on the /sys disk, for example, and remind yourself of all the great resources and libraries that are available there.

Finally, it may not be obvious that you can call findFile in your own programs! Any time you need the user to specify a file to load or operate on, consider using findFile to give them a nice UI to do so, rather than having them type a file name or path from memory. And if you need to customize the behavior β€” for example, to change the title or colors, or to provide a custom preview for your custom file type β€” you can import "textUtil", and then subclass textUtil.FileDialog, which is the workhorse behind the findFile function.

Have you been using findFile? Do you have ideas of how you might apply it (or the underlying FileDialog) in the future? Share your thoughts in the comments below!

tip Article's
30 articles in total
Favicon
Ctrl+Alt+Arrow (Right, Left) not working on IntelliJ
Favicon
if locals == globals
Favicon
Version Control Best Practices with Git and GitHub
Favicon
Creating generic types for API (backend) responses
Favicon
Null or Nothing? Unmasking the Mystery of Parameters in Dart
Favicon
List of prompts for successful affiliate marketing
Favicon
My impressions about the book The Clean Coder πŸ§ΉπŸ“š
Favicon
Why You Should Use GraphQL Playground ⏰
Favicon
Automate WEBP To PNG With A Simple .Bat File
Favicon
In CMS Made Simple, how do you change the theme?
Favicon
A importancia de fazer testes
Favicon
Conditional Styles with CSS :has
Favicon
Do you know that 0.1 + 0.2 is not equal to 0.3?
Favicon
How to save datetime data that is relevant to multiple countries or timeΒ zones?
Favicon
What I've Learned About Git from Senior Colleagues (Part 1 - git stash)
Favicon
A (somewhat) deep dive into TypeScript constructor intricacies, step-by-step
Favicon
Faster Color picking in Tailwind
Favicon
Evita usar UpperCase o LowerCase C#
Favicon
#DeveloperTipOfTheWeek - Application Security
Favicon
Running out of space on a developer's machine
Favicon
Alert vs confirm in javascript
Favicon
Quick Tip: Counting up to a limit
Favicon
Quick Tip: findFile
Favicon
Time Saving Tip #2 - User Snippets in VSCode
Favicon
Notify Yourself After Completing a Long-Running Bash Process
Favicon
Time Saving Tip #1 - Use Voice Dictation
Favicon
πŸš€ Unveiling the Power of OpenSearch in 202$: A Comprehensive Overview😎
Favicon
Quick Tip: Checking if a Number is in Range
Favicon
Building a TypeScript Simple Channel (Like Golang)
Favicon
Ubuntu Minimal Install

Featured ones: