Class: FileOP

Inherits:
Object
  • Object
show all
Defined in:
lib/memo_for_bin/FileOP.rb

Instance Method Summary collapse

Instance Method Details

#is_exist_and_mk_dir(dir_path: String) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/memo_for_bin/FileOP.rb', line 28

def is_exist_and_mk_dir(dir_path: String)
  if !Dir.exists?("#{dir_path}")
    FileUtils.mkdir_p("#{dir_path}")
    puts "created new Dir named #{dir_path}"
  else
    puts "#{dir_path} is already existed"
  end
end

#is_exist_and_mk_file(file_path: String) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/memo_for_bin/FileOP.rb', line 19

def is_exist_and_mk_file(file_path: String)
  if !File.exists?("#{file_path}")
    FileUtils.touch("#{file_path}")
    puts "created new File named #{file_path}"
  else
    puts "#{file_path} is already existed"
  end
end

#is_exist_and_rm_file(file_path: String) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/memo_for_bin/FileOP.rb', line 37

def is_exist_and_rm_file(file_path: String)
  if File.exists?("#{file_path}")
    FileUtils.rm("#{file_path}")
    puts "remove File named #{file_path}"
  else
    puts "#{file_path} is not  existed"
  end
end

#is_exist_dir_and_mk_files(checked_dir: String, files: [String]) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/memo_for_bin/FileOP.rb', line 5

def is_exist_dir_and_mk_files(checked_dir:String, files: [String])
  if !Dir.exists?("#{checked_dir}")
    p files
    files.each do |file|
      p file
      FileUtils.mkdir_p("#{checked_dir}")
      FileUtils.touch("#{checked_dir}/#{file}")
    end
    puts "created new Dir named #{checked_dir}"
  else
    puts "#{checked_dir} is already existed"
  end
end