浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Public Class methods

Changes the current working directory of the process to the given string. When called without an argument, changes the directory to the value of the environment variable HOME, or LOGDIR. SystemCallError (probably Errno::ENOENT) if the target directory does not exist.

If a block is given, it is passed the name of the new current directory, and the block is executed with that as the current directory. The original working directory is restored when the block exits. The return value of chdir is the value of the block. chdir blocks can be nested, but in a multi-threaded program an error will be raised if a thread attempts to open a chdir block while another thread has one open.

   Dir.chdir("/var/spool/mail")
   puts Dir.pwd
   Dir.chdir("/tmp") do
     puts Dir.pwd
     Dir.chdir("/usr") do
       puts Dir.pwd
     end
     puts Dir.pwd
   end
   puts Dir.pwd

produces:

   /var/spool/mail<br />   /tmp<br />   /usr<br />   /tmp<br />   /var/spool/mail<br />


posted on 2011-03-19 07:46  lexus  阅读(340)  评论(0编辑  收藏  举报