The [[CHDIR]] statement changes the program's location from one working directory to another by specifying a literal or variable [[STRING]] path. {{PageSyntax}} :[[CHDIR]] {{Parameter|path$}} {{PageDescription}} * {{Parameter|path$}} is the new directory path the program will work in. * {{Parameter|path$}} can be an absolute path (starting from the root folder) or relative path (starting from the current program location). * If {{Parameter|path$}} specifies a non-existing path, a [[ERROR Codes|"Path not found"]] error will occur. * '''A QB64 [[SHELL]] statement cannot use "CD " or "CHDIR " + path$ to change directories.''' {{PageExamples}} ''Example 1:'' The following code is Windows-specific: {{CodeStart}} '' '' {{Cl|CHDIR}} "C:\" 'change to the root drive C (absolute path) {{Cl|CHDIR}} "DOCUME~1" 'change to "C:\Documents and Settings" from root drive (relative path) {{Cl|CHDIR}} "..\" 'change back to previous folder one up '' '' {{CodeEnd}} :''Details:'' '''QB64''' can use long or short (8.3 notation) file and path names. ''Example 2:'' Using the Windows API to find the current program's name and root path. The PATH$ is a shared function value. {{CodeStart}} '' '' {{Cl|_TITLE}} "My program" {{Cl|PRINT}} TITLE$ {{Cl|PRINT}} PATH$ {{Cl|FUNCTION}} TITLE$ ''=== SHOW CURRENT PROGRAM {{Cl|SHARED}} PATH$ 'optional path information shared with main module only {{Cl|DECLARE LIBRARY}} 'Directory Information using KERNEL32 provided by Dav {{Cl|FUNCTION}} GetModuleFileNameA ({{Cl|BYVAL}} Module {{Cl|AS}} {{Cl|LONG}}, FileName {{Cl|AS}} {{Cl|STRING}}, {{Cl|BYVAL}} nSize {{Cl|AS}} {{Cl|LONG}}) {{Cl|DECLARE LIBRARY|END DECLARE}} FileName$ = {{Cl|SPACE$}}(256) Result = GetModuleFileNameA(0, FileName$, {{Cl|LEN}}(FileName$)) '0 designates the current program {{Cl|IF...THEN|IF}} Result {{Cl|THEN}} 'Result returns the length or bytes of the string information PATH$ = {{Cl|LEFT$}}(FileName$, Result) start = 1 DO posit = {{Cl|INSTR}}(start, PATH$, "\") {{Cl|IF...THEN|IF}} posit {{Cl|THEN}} last = posit start = posit + 1 {{Cl|LOOP}} {{Cl|UNTIL}} posit = 0 TITLE$ = {{Cl|MID$}}(PATH$, last + 1) PATH$ = {{Cl|LEFT$}}(PATH$, last) {{Cl|ELSE}} TITLE$ = "": PATH$ = "" {{Cl|END IF}} {{Cl|END FUNCTION}} '' '' {{CodeEnd}} : '''Note:''' The program's [[_TITLE]] name may be different from the actual program module's file name returned by Windows. {{PageSeeAlso}} * [[SHELL]], [[FILES]] * [[MKDIR]], [[RMDIR]] * [[$CONSOLE]] {{PageNavigation}} <