6.29. Ruby Dir classes and methods

发布时间 :2023-10-31 23:00:08 UTC      

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 .

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.