Folder and Drive FunctionsYou'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.
| mkdir, rmdir |
| chdir, chdrive, |
| curdir$, dir$, dir$ close, diskfree, disksize |
Current Directory/Folder
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.
Directory and Drive Functions Reference
Here's a quick reference of the available array functions, in alphabetical
order.
result$ = curdir$ ' current directory for default drive
result$ = curdir$ "d" ' each drive has a current directory
Full path, including drive, is returned.
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.
TYPE DirData
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
END TYPE
DIR$ CLOSE ' no arguments
Result&& = DiskFree ' default drive
Result&& = DiskFree("d") ' drive d:
Result&& = DiskFree("") ' default drive
Result&& = DiskFree("d") ' drive d:
CHDRIVE "d" ' changes current drive to d:
CHDRIVE "c:" ' colon is optional
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 "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 "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.