List files from selected folder in Notepad

Share your macros, knowledge, solutions, services, ...
Post Reply
Petr
Posts: 106
Joined: Tue Oct 18, 2016 1:12 pm

List files from selected folder in Notepad

Post by Petr » Wed Nov 23, 2016 4:47 pm

This example allows user to select a folder and then the macro opens Notepad and lists the folder content in it.

Code: Select all

<#> Start of the macro
<cmds>

<#> Get folder for counting files... 
<var_oper>(gm_vbiDirectory,"",SELECT_FOLDER,"","", "0")

<if_str>("_vCanceled==1")
   <exitmacro>
<endif>

<#> Get list of files in folder and count these files 
<file_enum>("%gm_vbiDirectory%\*.*",2,vTemp_Files,vTemp_NumOfFiles)

<if_num>("vTemp_NumOfFiles==0")

   <msg>(-100,-100,"No files found in selected directory.","Message",1)
   <exitmacro>

<endif>

<#> Start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)
<waitfor>("WIN","OPEN","[Untitled - Notepad|Notepad|#164|#18]",15,0)
<actwin>("[Untitled - Notepad|Notepad|#164|#18]",0,0,"no")
<if_win>("[Untitled - Notepad|Notepad|#164|#18]","ACT",0)

   <#> Write each file name to new line in Notepad 
   <begloop>(vTemp_NumOfFiles)
      <varout>("vTemp_Files[_vLoopCounter0]",2)
      <newline>
   <endloop>
<endif>
<#> End of the macro

Post Reply