Search code examples
windowsbatch-filepluginscmdsystem

MS-DOS "plugin" system?


Creating a program called Joker.cmd (https://github.com/nightmare-dll/Joker/), and it's basically done. Was basically me testing out github at first and turned into something I wouldn't mind fully releasing.

It's basically done, so I would love to implement a user plugin system. Dir tree is as of rightnow (not synced on github);

 data/
  -config.cmd
 plugins/
  - test1.cmd
  - test2.cmd
 joker.cmd

So then joker.cmd would list both "test1.cmd" and "test2.cmd" and have a

 set /p plugin=Plugin name; 
 start %plugin%.cmd

and then run the specified plugin. The only issue is how would I get joker.cmd to list only files ending in either .cmd or .bat?


Solution

  • How would I get joker.cmd to list only files ending in either .cmd or .bat?

    Add the following lines to joker.cmd to run the plugins automatically:

    for /f "tokens=*" %%f in ('dir /b plugins\*.cmd plugins\*.bat') do (
      start "" %%f
      )
    

    Add the following lines to joker.cmd to prompt for the plugin to run:

    dir /b plugins\*.cmd plugins\*.bat
    set /p plugin=Plugin name: 
    start "" plugins\%plugin%
    

    Note:

    • Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""

      According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.

    Source start


    Further Reading

    • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
    • dir - Display a list of files and subfolders.
    • for /f - Loop command against the results of another command.
    • start - Start a program, command or batch script (opens in a new window).