1 File Operations

1.1 Current User Directory

UI.puts "Dir. Home:#{Dir.home}"
Copy the code

1.2 Whether a directory exists

File.directory? (path)Copy the code

Return true if path is a directory

1.2 Whether a path exists

File.exist? (path)Copy the code

Return true if path exists

1.3 Parent directory of the current directory

Way # 1
File.expand_path("..", Dir.pwd)
Copy the code
Way # 2
File.dirname(Dir.pwd)
Copy the code

2. Print logs

aa = system('ls')    # system returns only whether the execution was successful, with true indicating that the execution was successful and any other value indicating that the execution failed
puts aa
puts '-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
bb = %x(ls)         Use %x to get the output of the command execution
puts bb
Copy the code

Results:

test.rb  test.txt  world.rb
true
-----------------------
test.rb
test.txt

Copy the code