<commit_before>require 'fileutils'

class FileManager
  @@stack = []
  
  def self.create_dir(a_name)
    @@stack.push(a_name)
    puts '     create ' + @@stack.join('/')
    FileUtils.mkdir_p(@@stack.join('/'))
    yield if block_given?
    @@stack.pop
  end
  
  def self.create_file(a_name)
    path = @@stack.empty? ? a_name : @@stack.join('/') + '/' + a_name
    FileManager.create_dir(path.sub(/\/[^\/]+$/, ''))
    puts "     #{File.exist?(a_name) ? 'update' : 'create'} " + path
    if block_given?
      open(path, 'w') { |io| io.write(yield) }
    else<commit_msg>fixed tiny bug which could cause some extra directories to be created sometimes<commit_after>require 'fileutils'

class FileManager
  @@stack = []
  
  def self.create_dir(a_name)
    @@stack.push(a_name)
    unless File.directory?(File.join(@@stack))
      puts '     create ' + @@stack.join('/')
      FileUtils.mkdir_p(@@stack.join('/'))
    end
    yield if block_given?
    @@stack.pop
  end
  
  def self.create_file(a_name)
    path = @@stack.empty? ? a_name : @@stack.join('/') + '/' + a_name
    FileManager.create_dir(path.sub(/\/[^\/]+$/, '')) if @@stack.empty?
    puts "     #{File.exist?(a_name) ? 'update' : 'create'} " + path
    if block_given?
      open(path, 'w') { |io| io.write(yield) }
    else
{'fraction_non_alphanumeric': 0.18977536793183578, 'fraction_numerical': 0.0, 'mean_word_length': 2.9510703363914375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7030946', 'n_tokens_mistral': 490, 'n_tokens_neox': 474, 'n_words': 90}