Table of contents
TOC
折叠目录
展开目录

ChDir 语句ChDir Statement

office 365 dev account|上次更新日期: 2018/4/3
|
2 参与人员

更改当前目录或文件夹。Changes the current directory or folder.

语法Syntax

ChDirpathChDirpath

所需的_路径_参数是一个字符串表达式,用于标识哪个目录或文件夹变成新的默认目录或文件夹。The required pathargument is a string expression that identifies which directory or folder becomes the new default directory or folder.路径_可以包含驱动器。The _path may include the drive.如果未指定驱动器, ChDir 会更改当前驱动器上的默认目录或文件夹。If no drive is specified, ChDir changes the default directory or folder on the current drive.

备注Remarks

ChDir语句更改的默认目录或文件夹,但不更改默认驱动器。The ChDir statement changes the default directory or folder but does not change the default drive.一个不同的语句, ChDrive,更改默认驱动器。A different statement, ChDrive, changes the default drive.

ChDir "D:\TMP" ' Make "D:\TMP" the current folder. 

ChDrive "D"    ' Make "D" the current drive. 

在电源 Macintosh 上,默认驱动器始终更改_路径_中指定的驱动器。On the Power Macintosh, the default drive always changes to the drive specified in path.完整路径指定以卷名开头,相对路径以冒号 ( : ) 开头。Full path specifications begin with the volume name, and relative paths begin with a colon ( : ).ChDir 将解析路径中指定的任何别名:ChDir resolves any aliases specified in the path:

ChDir "MacDrive:Tmp" ' On the Macintosh. 

请注意,在进行相对路径更改时,Microsoft Windows 和 Macintosh 中使用的符号不同:Note that when making relative directory changes, different symbols are used in Microsoft Windows and on the Macintosh:

ChDir ".." ' Moves up one directory in Microsoft Windows. 
ChDir "::" ' Moves up one directory on the Macintosh.

在 Macintosh 上,默认驱动器名称为"HD",路径名称的各个部分由冒号而不是反斜线分隔开。On the Macintosh, the default drive name is "HD" and portions of the pathname are separated by colons instead of backslashes.同样,您可以指定 Macintosh 文件夹而不是 Windows。Similarly, you would specify Macintosh folders instead of Windows.最后,通配符在 Macintosh 中没有特殊意义,仅视为字符。Finally, wildcard characters have no special meaning on the Macintosh and are treated simply as characters.

示例Example

此示例使用ChDir语句来更改当前目录或文件夹。This example uses the ChDir statement to change the current directory or folder.如果默认驱动器是 C,则默认的驱动器保持 C,即使默认文件夹更改为 d: 驱动器上的文件夹If the default drive is C, then default drive remains C, even though the default folder changes to a folder on drive D:

' Assume "C:" is the current drive. The following statement changes 
' the default directory on drive "D:". "C:" remains the current drive. 
ChDir "D:\WINDOWS\SYSTEM" 

另请参阅See also

参考Reference

ChDriveChDrive

CurDirCurDir

MkDirMkDir

RmDirRmDir

© 2018 Microsoft