ChangeDir dir$
Parameters
| dir$ - directory to make current (absolute, or relative to the current directory) |
Description
|
Changes the current directory that relative file paths are resolved against. Every file command that takes a path (LoadImage, ReadFile, ReadDir and the rest) resolves relative paths against the current directory. When you run from the IDE that starts as the folder containing your source file, which is why "media\ship.png" style paths just work. ChangeDir moves that base folder - handy when a game keeps its data in a subfolder, or a tool needs to walk somewhere else. Use ".." to step up to the parent directory (at the root of a drive it stays put). ChangeDir does not complain if the directory does not exist - nothing changes and no error is raised - so check CurrentDir$() afterwards if you need to be sure it worked. See also: CurrentDir, CreateDir, ReadDir. |
Example
; ChangeDir Example ; ----------------- ; Remember where we started Print "Starting folder: "+CurrentDir$() ; Create a demo folder and make it the current directory CreateDir "demo_folder" ChangeDir "demo_folder" Print "After ChangeDir: "+CurrentDir$() ; Relative file operations now happen inside demo_folder file=WriteFile("save.txt") WriteLine file,"saved inside demo_folder" CloseFile file Print "Wrote save.txt (it landed inside demo_folder)" ; ".." changes to the parent folder ChangeDir ".." Print "After ChangeDir '..': "+CurrentDir$() ; Clean up the folder and file the example created DeleteFile "demo_folder\save.txt" DeleteDir "demo_folder" Print "Cleaned up demo_folder" Print "" Print "Press any key to close the example" WaitKey End
Index