mdc/bin/notes_handling.rb
##
# Recursively parse the given folder and return a
# tree containing all found data
# @param [String] directory of the root folder of the notes storage
# @param [String] folder the folder to add data to
# @return [Folder] root folder
Recursively parse the given folder and return a
tree containing all found data
Recursively parse the given folder and return a tree containing all found data
def parse_folder(directory, folder, first = false)
    directory.tr!('\\', '/')
    directory =~ %r{.*/(.*?)$}
    folder.name = first ? '' : Regexp.last_match(1)
    if File.exist?("#{directory}/folder.properties")
      props = Parsing::PropertiesReader.new("#{directory}/folder.properties")
      folder.title = props['title']
      folder.description = props['description']
    else
      folder.title = folder.name
      folder.description = ''
    end
    Dir.foreach(directory) do |d|
      next if d.end_with?('.')
      path = "#{directory}/#{d}"
      if File.file?(path) && d.end_with?('.txt', '.md')
        entry = Notes::FolderEntry.new(d)
        folder << entry
      elsif File.directory?(path)
        sub_folder = Notes::Folder.new(path, '', '', '')
        parse_folder(path, sub_folder)
        folder.add_folder(sub_folder)
      end
    end
  end
def parse_folder ( directory , folder , first = false ) directory . tr! ( '\\' , '/' ) directory =~ %r{ .*/(.*?)$ } folder . name = first ? '' : Regexp . last_match ( 1 ) if File . exist? ( "#{directory}/folder.properties" ) props = Parsing :: PropertiesReader . new ( "#{directory}/folder.properties" ) folder . title = props [ 'title' ] folder . description = props [ 'description' ] else folder . title = folder . name folder . description = '' end Dir . foreach ( directory ) do | d | next if d . end_with? ( '.' ) path = "#{directory}/#{d}" if File . file? ( path ) && d . end_with? ( '.txt' , '.md' ) entry = Notes :: FolderEntry . new ( d ) folder << entry elsif File . directory? ( path ) sub_folder = Notes :: Folder . new ( path , '' , '' , '' ) parse_folder ( path , sub_folder ) folder . add_folder ( sub_folder ) end end end
Recursively parse the given folder and return a
tree containing all found data
Recursively parse the given folder and return a tree containing all found data
# Unify to Unix file separators # Get last part of the path # Check for properties # Search for files in folder
None
Folder
directory
<not_specific>
folder
<not_specific>
first
<not_specific>
<not_specific>
folder the folder to add data to
folder the folder to add data to