ink File.symlink("/etc/hosts","/tmp/hosts") # symbolic link File.truncate("myfile",1000) # Now at most 1000 bytes
fileUtils 也有很多有用的方法 代码: 代码: require "fileutils" same = FileUtilspare_file("alpha","beta") # true # Copy epsilon to theta and log any errors. FileUtils.copy("epsilon","theta", true) FileUtils.move("/tmp/names","/etc") # Move to new directory FileUtils.move("colours","colors") # Just a rename FileUtils.safe_unlink("alpha","beta","gamma") # Log errors on the next two files FileUtils.safe_unlink("delta","epsilon",true) FileUtils.install("foo.so","/usr/lib")
9 从键盘抓取输入 也就是抓取用户从键盘输入的字符。 unix 平台: 代码: 代码: def getchar system("stty raw -echo") # Raw mode, no echo char = STDIN.getc system("stty -raw echo") # Reset terminal mode char end
windows 平台: 代码: 代码:
require 'Win32API' def getc