Help Center
Help CenterFreeBASIC

ChDirfunction

Changes the current drive and directory

Operating System Functionsfunctiondocumented

Syntax

Declare Function ChDir ( ByRef path As Const String ) As Long

Parameters

NameDescription
pathA String argument specifying the path to change to.

Return value


Returns zero (0) on success and negative one (-1) on failure.

Description


Changes the current drive and directory to that specified.

Remarks

Usage


result = ChDir( path )

Platform Differences


  • Linux requires the filename case matches the real name of the file. Windows and DOS are case insensitive.
  • Path separators in Linux are forward slashes / . Windows uses backward slashes \ but it allows for forward slashes . DOS uses backward \ slashes.

Differences from QB


  • In QB, the drive could not be specified.

See also


Example


Dim pathname As String = $"x:\folder"

Dim result As Long = ChDir(pathname)



If result <> 0 Then Print "error changing current directory to " & pathname & "."

Reference

  • Documented in KeyPgChdir.html