6.29. Ruby Dir classes and methods

发布时间 : 2025-10-25 13:34:02 UTC      

Page Views: 9 views

Dir is a directory stream that represents a file name in a directory in the operating system. Dir classes also have directory-related operations, such as matching wildcard file names, changing working directories, and so on.

6.29.1. Class method #

Serial number

Method and description

1

Dir[pat] Dir::glob( pat) Returns an array containing the specified wildcard pattern pat matching file name: * -match contains null any string of a string ** -Recursively match any string ? -match any single character [...] -matches any of the closed characters {a,b...} -matches any one of the strings Dir["foo.*"] # Match "foo.c"、 "foo.rb" etc., Dir["foo.?"] # Match "foo.c"、 "foo.h" Wait

2

Dir::chdir( path) Change the current directory.

3

Dir::chroot( path) Change the root directory (only superusers are allowed). It is not available on all platforms.

4

Dir::delete( path) delete path the specified directory. The directory must be empty.

5

Dir::entries( path) Returns an array containing directories path the file name in the.

6

Dir::foreach( path) {| f| ...} for path each file in the specified directory executes the block once.

7

Dir::getwd Dir::pwd Return to the current directory.

8

Dir::mkdir( path[, mode=0777]) Create path the specified directory.The permission mode can be used File::umask will be ignored on Win32 platforms.

9

Dir::new( path) Dir::open( path) Dir::open( path) {| dir| ...} Return path gets or sets the new directory object of If open given a block, the new directory object is passed to the block, andthe block closes the directory object before terminating.

10

Dir::pwd see Dir::getwd.

11

Dir::rmdir( path) Dir::unlink( path) Dir::delete( path) Deletes the directory specified by path. The directory must be empty.

6.29.2. Example method #

Hypothetical d is an instance of Dir class:

Serial number

Method & description

1

d.close Close the directory stream.

2

d.each {| f| ...} Execute the block once for each entry in d.

3

d.pos d.tell Returns the current position in d.

4

d.pos= offset Sets the location in the directory stream.

5

d.pos= pos d.seek(pos) Move to a location in d. Pos must be a value or 0 returned by d.pos.

6

d.read Returns the next entry for d.

7

d.rewind Move the position in d to the first entry.

8

d.seek(po s) see also d.pos=pos .

9

d.tell see also d.pos .

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。