Save list of files in given folder to a text file

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

Save list of files in given folder to a text file

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

This example retrieves the list of files in the given folder and saves the list in a text file.

Code: Select all

<cmds>
<#>  Declare variable containing resulting file
<varset>("vResultFile=%temp%\fileList.txt","")

<#> Form for user input
<form_item>("form1","Folder to enumerate:","EDIT_FOLDER","%temp%","vSourceFolder")
<form_item>("form1","Save file list to file:","EDIT_FILE","vResultFile","vResultFile")
<form_show>("form1","Select folder to read files from","shell32.dll",0,,0,,,1)

<#> Exit macro if user cancels the input form
<if_str>("_vCanceled==1")
   <exitmacro>
<endif>

<#> Enumerate files in the user selected folder, files are stored in vFile variable array
<file_enum>("%vSourceFolder%\*",3,vFile,vNumOfFiles)

<#> Loop the vFile array
<for>("i=0","i < vNumOfFiles","1")

   <#> Save the file name...
   <data_save>("vFile[i]","vResultFile","A")

   <#> ... and add new line.
   <data_save>("%_vKeyCR%%_vKeyNewLine%","vResultFile","A")

<for_end>

<#>Open file with the results
<execappex>("%vResultFile%","","",0,0)

<#> End of the macro

Post Reply