openstudiocore/src/cli/embedded_help.rb
# Finds files relative to a given location whose names
# (not including file extension) match the regex
# and whose extension matches the specified extension.
# Recursively includes files in subdirectories below the given location.
#
# @param path [String] the directory to search relative to the current file.
#   Use ./ for the current directory
# @param file_name_regexp [Regexp] the Ruby regular expression to match the file name
#   (including the file extension).
# @return [Array<String>] an array of absolute file paths matching the specified string
Finds files relative to a given location whose names
(not including file extension) match the regex
and whose extension matches the specified extension.
Recursively includes files in subdirectories below the given location.
Finds files relative to a given location whose names ( not including file extension ) match the regex and whose extension matches the specified extension . Recursively includes files in subdirectories below the given location .
def embedded_files_relative(path, file_name_regexp)
    absolute_path = File.dirname(caller_locations(1,1)[0].path) + '/' + path
    if absolute_path.chars.first == ':'
      absolute_path[0] = ''
      absolute_path = File.expand_path absolute_path
      if /[A-Z]\:/.match(absolute_path)
        absolute_path = absolute_path[2..-1]
      end
      absolute_path = ':' + absolute_path
    end
    matches = []
    EmbeddedScripting.allFileNamesAsString.split(';').each do |file|
      next unless file.start_with?(absolute_path)
      next unless File.basename(file).match(file_name_regexp)
      matches << file
    end
    return matches
  end
def embedded_files_relative ( path , file_name_regexp ) absolute_path = File . dirname ( caller_locations ( 1 , 1 ) [ 0 ] . path ) + '/' + path if absolute_path . chars . first == ':' absolute_path [ 0 ] = '' absolute_path = File . expand_path absolute_path if / [A-Z] \: / . match ( absolute_path ) absolute_path = absolute_path [ 2 .. - 1 ] end absolute_path = ':' + absolute_path end matches = [ ] EmbeddedScripting . allFileNamesAsString . split ( ';' ) . each do | file | next unless file . start_with? ( absolute_path ) next unless File . basename ( file ) . match ( file_name_regexp ) matches << file end return matches end
Finds files relative to a given location whose names
(not including file extension) match the regex
and whose extension matches the specified extension.
Finds files relative to a given location whose names ( not including file extension ) match the regex and whose extension matches the specified extension .
# Resolve the absolute path to the caller location # strip Windows drive letters # Loop through all the files in the embedded system # Skip files outside of the specified directory # Skip files that don't match the file_name_pattern criterion # If here, found a match
an array of absolute file paths matching the specified string
an array of absolute file paths matching the specified string
Array<String>
path
the directory to search relative to the current file. Use ./ for the current directory
the directory to search relative to the current file . Use . / for the current directory
file_name_regexp
the Ruby regular expression to match the file name (including the file extension).
the Ruby regular expression to match the file name ( including the file extension ) .