PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC -
the scope of the language as well as it's specific capabilities.
Folder and Drive Functions
PowerBASIC several functions which support the creation and
navigation of folders, which can be categorized as follows.
You'll note that the functions use "dir" (directory) instead
of the an abbreviation for folder. This simply reflects that
the use of "directory" was in vogue when the PowerBASIC functions
were first named.
curdir$, dir$, dir$ close, diskfree, disksize
When an application runs, Windows assigns the drive/directory of the EXE as
the current folder and drive. PowerBASIC provides several functions to
return or change both of these.
Directory and Drive Functions Listing
Here's a simple listing of the directory/drive functions above, with a one-line
description of what the function does. Syntax and examples are given
in the next section.
- CHDIR - Change the current (default) directory on a given drive
- CHDRIVE - Change the current default drive
- CURDIR$ - Return the current directory for a given drive
- DIR$ - Return a filename that matches the given mask
- DIR$ CLOSE - Force the release the operating system FindNext handle
- DISKFREE - Return the amount of available space of a disk, in bytes
- DISKSIZE - Return the total amount of space on a disk, in bytes
- MKDIR - Create a subdirectory/folder (like the DOS MKDIR command)
- NAME - Rename a file or a directory (like the DOS REN command)
- PATHNAME$ - Parse a path/file name to extract component parts
Directory and Drive Functions Reference
Here's a quick reference of the available array functions, in alphabetical
- curdir$ - returns current directory pathname
result$ = curdir$ ' current directory for default drive
result$ = curdir$ "d" ' each drive has a current directory
Full path, including drive, is returned.
- dir$ - returns matching file/folder names
result$ = dir$("*.bas") ' 1st file with .bas extension
result$ = dir$("d:\*.txt") ' file not in current folder
result$ = dir$ ' next file with last mask
result$ = dir$("*.bas", %Hidden+%System) 'normal/hidden/system
result$ = dir$("*.bas", ONLY %Hidden) 'normal/hidden/system
result$ = dir$("*.bas", %SubDir 'directories only
result$ = dir$("d", %VLabel 'volume label, ignores mask
ONLY Values - (use #INCLUDE "Win32API.inc" in source code):
%NORMAL (0) %SYSTEM (4) %SUBDIR (16)
%HIDDEN (2) %VLABEL (8)
Dim x As DirData ' see below for DirData explanation
a$ = DIR$("*.txt", TO x) ' attributes put in x
attrib$ operation is to return normal files and filenames
with specific attributes. Use ONLY to exclude normal files.
To get volume label, mask must include drive letter. If path
entered, only 1st character is used.
When result$ = "", there are no more matching filenames.
The following data type is built into PowerBASIC.
FileAttributes AS DWORD
CreationTime AS QUAD
LastAccessTime AS QUAD
LastWriteTime AS QUAD
FileSizeHigh AS DWORD
FileSizeLow AS DWORD
Reserved0 AS DWORD
Reserved1 AS DWORD
FileName AS ASCIIZ * 260
ShortName AS ASCIIZ * 14
- dir$ close - release FindNext handle
DIR$ CLOSE ' no arguments
- diskfree - returns available space (bytes)
Result&& = DiskFree ' default drive
Result&& = DiskFree("d") ' drive d:
- disksize - returns total size of disk (bytes)
Result&& = DiskFree("") ' default drive
Result&& = DiskFree("d") ' drive d:
- chdrive - change default drive
CHDRIVE "d" ' changes current drive to d:
CHDRIVE "c:" ' colon is optional
- chdir - change default directory of current drive
chdir "\download" ' absolute path
chdir "..\newfolder" ' relative location
chdir "d:\data" ' sets default directory of drive d:
' current directory is not changed!
Directory can be absolute or relative. Does not change
the current default drive.
- mkdir - create folder
mkdir "c:\data" ' creates folder in specific path
mkdir "newfolder" ' creates folder below current folder
The folder must NOT exist and it's parent folder MUST exist.
- rmdir - removes folder
rmdir "temp" ' remove temp folder below current folder
rmdir "c:\download" ' removes folder with specific pathname
The folder must be empty! Directory cannot be the current directory.
If you have any suggestions or corrections, please let me know.