How to resolve the algorithm Walk a directory/Non-recursively step by step in the M2000 Interpreter programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Walk a directory/Non-recursively step by step in the M2000 Interpreter programming language

Table of Contents

Problem Statement

Walk a given directory and print the names of files matching a given pattern.
(How is "pattern" defined? substring match? DOS pattern? BASH pattern? ZSH pattern? Perl regular expression?)

Note: This task is for non-recursive methods.   These tasks should read a single directory, not an entire directory tree.
Note: Please be careful when running any code presented here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Walk a directory/Non-recursively step by step in the M2000 Interpreter programming language

Source code in the m2000 programming language

Module Show_Files_Standard {
      \\ we get more (include hidden too)
      Module InnerWay (folder_path$, pattern$){
            olddir$=dir$
            dir folder_path$
            \\ clear menu list
            Menu
            \\ + place export to menu, without showing
            \\ ! sort to name
            files ! + pattern$
            If MenuItems>0 then {
                  For i=1 to MenuItems {
                        Print Menu$(i)+".exe"
                  }
            }
            dir olddir$
      }
      InnerWay "C:\Windows","*.exe"
}
Show_Files_Standard

Module Show_Files {
      Function  get_files$ (folder_path$) {
            \\ we get second argument using letter$ which pop from stack
            pattern$=lcase$(Letter$)
            Declare  objfso "Scripting.FileSystemObject"
            Method objfso, "GetFolder", folder_path$ as fc
            With fc, "files" set files
            \\ from revision 13 - version 9.4
            With files, -4& as EnumFile
            With EnumFile, "Name" as name$
            Dim empty$()
            =empty$()
            Stack New {
                  While EnumFile {
                        If lcase$(name$) ~ pattern$ Then Data name$
                  }
                  \\ get stack values and fill an array
                  =Array$([])
            }
      }
      Dim Name$()
      Name$()=get_files$("C:\Windows","*.exe")
      m=each(Name$())
      While m {
            Print Array$(m)
      }
}
Show_Files

  

You may also check:How to resolve the algorithm Hamming numbers step by step in the Julia programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the Ruby programming language
You may also check:How to resolve the algorithm Host introspection step by step in the Haskell programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Hello world/Line printer step by step in the MIXAL programming language