我有实际的目录路径:C:\Documents and Settings\Matt\
现在我在这里尝试Dir::chdir()
看看它是如何工作的。
C:\Documents and Settings\Matt>cd..
C:\Documents and Settings>cd..
C:\>irb
irb(main):001:0> Dir.pwd
=> "C:/"
irb(main):002:0> Dir.chdir('\Documents and Settings')
=> 0
irb(main):003:0> Dir.pwd
=> "C:/Documents and Settings"
现在下面为什么会出现错误,而之前pwd
显示当前目录更改为"C:\Documents and Settings"
?
irb(main):004:0> Dir.chdir('\Matt')
Errno::ENOENT: No such file or directory - \Matt
from (irb):4:in `chdir'
from (irb):4
from C:/Ruby193/bin/irb:12:in `<main>'
但在它下面有效 - 这是否意味着 chdir 没有将目录更改为"C:\Documents and Settings"
?从C:\
我用的时候开始Dir.chdir('\Documents and Settings')
?
irb(main):005:0> Dir.chdir('\Documents and Settings\Matt')
=> 0
irb(main):006:0> Dir.pwd
=> "C:/Documents and Settings/Matt"
irb(main):007:0>