Collecting File Information from Windows Folders Using AutoHotkey

In Order to Manage Scripts Launched from the Windows Startup Folder, We Must First Know the Folder’s Contents

Last time in “Auto-Loading AutoHotkey Scripts When Booting Windows,” I highlighted the problem introduced by launching scripts from the Windows Startup folder on boot up—too many AutoHotkey icons in the System Tray might overwhelm the status bar. We can turn off the icons, but that’s like turning out the lights in an unlighted, windowless room full of furniture. You don’t know what’s where. We need a handy system for consolidating the information sitting in the Startup folder without making it too intrusive.

This time I demonstrate one technique for consolidating the Startup folder data for display. I have yet to settle on how I want to display the information and use the data. I see a number of possibilities:

  1. A single MsgBox listing the Startup shortcuts—the simplest, yet least flexible approach.
  2. A single System Tray icon right-click menu listing the Startup shortcuts—more flexible but limited in action creating techniques.
  3. A GUI window using a ListView control displaying the Startup folder’s shortcut data—the most flexible and powerful approach but more complicated to implement.

The MsgBox Technique

The message box (MsgBox command) provides the easiest method for displaying data, but it also offers the least flexibility. You’ll find the MsgBox limited to displaying text and a few buttons—although the available buttons do offer some tailoring options. (See Chapter 13.1.5 “Optimizing the AutoHotkey Message Box” of my book Jack’s Motley Assortment of AutoHotkey Tips for tips on how to add and tailor MsgBox buttons and actions.)

The image displays the shortcuts added to my Windows Startup folder for auto-loading on boot up, as well as, the target file path and name. (See the code for this MsgBox toward the end of this blog.)

While the MsgBox displays all the shortcuts in the Startup folder, it offers only information text. To add any significant action requires more work—even if only instructional pop-up windows.

The System Tray Right-click Menu

The Menu command offers a method for displaying the Startup menu items in a System Tray right-click menu while adding opportunities to incorporate action. Although more complicated than using a MsgBox, a Menu offers increased versatility by adding submenus and calling subroutines or functions.

On the downside, AutoHotkey menus have their limitations—although you can find tricks to avoid some of those constraints. The basic Menu command offers only a couple of built-in variables for immediate use. You’ll find adding more directly accessible variables a little more difficult (as referenced in Chapter 6.1.2 “More AutoHotkey Entertainment and Education” of Jack’s Motley Assortment of AutoHotkey Tips and discussed in “Use BoundFunc Object [Func.Bind()] to Pass GUI Control Data (An AutoHotkey GUI Revelation)” and “Increase the Flexibility of Menus by Passing Data with the BoundFunc Object” for Menu command-specific techniques).

I’m looking at writing a simple demonstration of a menu that provides a help window for each auto-launched AutoHotkey script for a future blog.

Graphical User Interface (GUI) Windows

The most versatile of the three options, an AutoHotkey script can tailor a GUI for multiple tasks while storing key information about the shortcuts (and their targets) in the Windows Startup folder. With a little design, the GUI window can act as the ultimate AutoHotkey Startup Control Center.

The image of the AutoHotkeyControl.ahk window displays an example of a possible method for controlling scripts from AutoHotkey using a GUI. Although not exactly what we want, it does demonstrate some possibilities.

But, regardless of which approach we take, the script must collect the data.

A List of Shortcuts in the Windows Startup Folder

Found in the AutoStartupToggle.ahk script, the Ctrl+Win+4 Hotkey combination reads the files in the Startup folder, weeds out the non-shortcuts, and displays a list of target file paths and names—plus the shortcut names:

	files := ""
	Loop %A_Startup%\*.*
		FileGetShortcut, %A_LoopFileFullPath%, Location
		If ErrorLevel
		files = %files%%Location%`n%A_LoopFileName%`n
	MsgBox,,Startup Folder List, %files%

Using the Loop (files & folders) command, the routine checks each file in the folder for shortcuts using the FileGetShortcut command. If not a shortcut (If ErrorLevel), the Loop jumps to the next entry. Otherwise, it adds the data to the variable files. The MsgBox command displays the results.

Regardless of which approach we take to controlling our AutoHotkey auto-start scripts, we need this first data-collecting step. Next time, I’ll attempt to insert the results into a menu.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

2 thoughts on “Collecting File Information from Windows Folders Using AutoHotkey

  1. Hallo Jack

    You might want to check out AHK Startup by Fanatic Guru. It solves some problems that you already face in this regard, and perhaps some more that you’d still run into.

    One of those pretty amazing solutions that some code genius come up with and share with the community.

    Brilliantly programmed, but for me personally not useful, is also “lintalist”. Also a script really worth checking out, I find !

    Kind regards, Hauke


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s