Repository navigation
SysWin System Folders
Home › All Categories › sys/win › System folders
Returns the paths of the Windows, system and temporary folders and of known folders.
Never write C:\Windows or C:\Users\... into a program: Windows can be installed on another
drive, and the user's folders can be moved or redirected. Ask for the folder instead.
Folders that belong to the user (Documents, the desktop, application data) are known folders,
each named by a FOLDERID_* constant; GetKnownFolderPath returns their
paths. The older CSIDL_* numbers still work through
GetSpecialFolderLocation.
Every path comes back as a ustring without a trailing backslash, except the temporary folder,
which has one.
#import "sys/win"
using winA console program that prints where Windows keeps things on this computer:
#import "sys/win"
using win
function main() as long
print "Windows: "; GetWinDir()
print "system: "; GetSystemDirectory()
print "system drive: "; GetSystemDrive()
print "temporary: "; GetTempPath()
print "documents: "; GetKnownFolderPath( @FOLDERID_Documents )
print "fonts: "; GetSpecialFolderLocation( CSIDL_FONTS )
print "user32.dll: "; GetSystemDllPath( "user32.dll" )
return 0
end function
end main()On a typical installation it prints C:\Windows, C:\Windows\system32, C:,
C:\Users\<name>\AppData\Local\Temp\, C:\Users\<name>\Documents, C:\Windows\Fonts and
C:\Windows\System32\USER32.dll.
| Function | Does |
|---|---|
| GetWinDir | Returns the Windows folder. |
| GetTempPath | Returns the folder for temporary files, with a trailing backslash. |
| GetSystemDrive | Returns the drive Windows is installed on, such as C:. |
| GetSystemDirectory | Returns the Windows system folder. |
| GetSystemWow64Directory | Returns the folder of the 32-bit system files on a 64-bit Windows. |
| GetSystemDllPath | Returns the full path of the DLL Windows loads for a name. |
| GetKnownFolderPath | Returns the path of a known folder, named by a FOLDERID_* constant. |
| GetSpecialFolderLocation | Returns the path of a special folder, named by a CSIDL_* value. |
function GetWinDir() as ustringReturns the path of the Windows folder, such as C:\Windows, without a trailing backslash.
Returns the path, or an empty string on failure.
Example
print "Windows is in "; GetWinDir()Microsoft Learn: GetWindowsDirectoryW
function GetTempPath overload() as ustringReturns the folder for temporary files, with a trailing backslash, so a file name can be
added straight on. It is the folder named by the TMP or TEMP environment variable, usually
C:\Users\<name>\AppData\Local\Temp\.
The Windows function of the same name, which fills a buffer, is still there with two arguments.
Returns the path, or an empty string on failure.
Example
dim ustrFile as ustring = GetTempPath() & "report.txt"
print ustrFileMicrosoft Learn: GetTempPathW
function GetSystemDrive() as ustringReturns the drive Windows is installed on, as a letter and a colon: C:. It is the first two
characters of the Windows folder.
Returns the drive.
Example
print "Windows is on drive "; GetSystemDrive()function GetSystemDirectory overload() as ustringReturns the path of the Windows system folder, where the system DLLs are: C:\Windows\system32
on a typical installation, without a trailing backslash. A 64-bit program gets the 64-bit system
folder.
The Windows function of the same name, which fills a buffer, is still there with two arguments.
Returns the path, or an empty string on failure.
Example
print GetSystemDirectory() & "\notepad.exe"Microsoft Learn: GetSystemDirectoryW
function GetSystemWow64Directory overload() as ustringReturns the folder that holds the 32-bit system files on a 64-bit Windows: C:\Windows\SysWOW64
on a typical installation.
The string returned ends in a null character after the path, so it is one character longer than
the path (20 rather than 19 for C:\Windows\SysWOW64). Printing it shows the path; before joining
a file name to it or comparing it, take the part before the null as the example does.
The Windows function of the same name, which fills a buffer, is still there with two arguments.
Returns the path, or an empty string on a 32-bit Windows, which has no such folder.
Example
dim ustrWow as ustring = GetSystemWow64Directory()
dim ustrPath as ustring = *cast( wstring ptr, strptr( ustrWow ) ) ' the path without the null
print ustrPath; len( ustrPath )Microsoft Learn: GetSystemWow64DirectoryW
function GetSystemDllPath( byval pwszDllName as const wstring ptr ) as ustringReturns the full path of the DLL that Windows loads for a name, such as
C:\Windows\System32\USER32.dll for user32.dll. The DLL is loaded to find out and released
again, so its start-up code runs; the name is looked up the way Windows looks up any DLL, so it
need not be a system DLL. The capitals in the path are the ones Windows reports.
| Parameter | Meaning |
|---|---|
pwszDllName |
The DLL's file name, with or without a path. |
Returns the path, or an empty string if the DLL could not be loaded.
Example
print "the common controls: "; GetSystemDllPath( "comctl32.dll" )Microsoft Learn: GetModuleFileNameW
function GetKnownFolderPath( byval rfid as const KNOWNFOLDERID const ptr, byval dwFlags as DWORD = 0, byval hToken as HANDLE = NULL ) as ustringReturns the path of a known folder: Documents (FOLDERID_Documents), the desktop
(FOLDERID_Desktop), roaming application data (FOLDERID_RoamingAppData), local application
data (FOLDERID_LocalAppData), Program Files (FOLDERID_ProgramFiles) and many more. Pass the
address of the constant.
A known folder can be listed by Windows and still not exist on a given computer; then the call
fails unless dwFlags asks for it to be created.
| Parameter | Meaning |
|---|---|
rfid |
The address of a FOLDERID_* constant. |
dwFlags |
0, or KF_FLAG_* values: KF_FLAG_CREATE creates the folder if it is missing, KF_FLAG_DONT_VERIFY returns the path without checking it. |
hToken |
NULL for the current user. An access token gives another user's folder, and cast(HANDLE, -1) the default profile copied into new accounts (that needs administrator rights). |
Returns the path, or an empty string on failure.
Example
dim ustrData as ustring = GetKnownFolderPath( @FOLDERID_RoamingAppData, KF_FLAG_CREATE )
print "settings go in "; ustrData & "\MyProgram"Microsoft Learn: SHGetKnownFolderPath, KNOWNFOLDERID
function GetSpecialFolderLocation( byval nFolder as long ) as ustringReturns the path of a special folder named by a CSIDL_* value: CSIDL_FONTS,
CSIDL_PERSONAL (Documents), CSIDL_APPDATA, CSIDL_WINDOWS and so on. The CSIDL_* values
are the older form of the known folders; prefer GetKnownFolderPath in new
code. A virtual folder with no path in the file system, such as CSIDL_PRINTERS, gives an empty
string.
| Parameter | Meaning |
|---|---|
nFolder |
A CSIDL_* value. |
Returns the path, or an empty string on failure.
Example
print "fonts are in "; GetSpecialFolderLocation( CSIDL_FONTS )Microsoft Learn: SHGetSpecialFolderLocation, CSIDL
- Category: sys/win
- Paths and files for the program's own folder
- Windows version and system
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing