# BlitzMax/Modules/System/File system

The BlitzMax filesystem module contains commands to perform operations on the computer's files and directories.
OpenFile, ReadFile and WriteFile return a stream object for reading and or writing data to files.
Directories can be examined file by file using a combination of the ReadDir, NextFile and CloseDir commands, or LoadDir can be used to read the file names of a directory into a string array.
File properties can be examined with the FileType, FileTime, FileSize and FileMode commands.
Files and directories (folders) can be created and deleted with the CreateFile, CreateDir DeleteFile and DeleteDir commands.
Finally, the FileSystem module contains various utility functions for handling file paths in a system independent manner. These commands include RealPath, StripDir, StripExt, StripAll, ExtractDir and ExtractExt.

# Functions
## StripDir

Function StripDir$( path$ )
Description: Strip directory from a file path
Example:

## StripExt

Function StripExt$( path$ )
Description: Strip extension from a file path
Example:

## StripAll

Function StripAll$( path$ )
Description: Strip directory and extension from a file path
Example:

## StripSlash

Function StripSlash$( path$ )
Description: Strip trailing slash from a file path
Information: StripSlash will not remove the trailing slash from a 'root' path. For example, "/" or (on Win32 only) "C:/".
Example:

## ExtractDir

Function ExtractDir$( path$ )
Description: Extract directory from a file path
Example:

## ExtractExt

Function ExtractExt$( path$ )
Description: Extract extension from a file path
Example:

## CurrentDir

Function CurrentDir$
Description: Get Current Directory
Returns: The current directory
Example:

## RealPath

Function RealPath$( path$ )
Description: Get real, absolute path of a file path
Example:

## FileType

Function FileType( path$ )
Description: Get file type
Returns: 0 if file at path doesn't exist, FILETYPE_FILE (1) if the file is a plain file or FILETYPE_DIR (2) if the file is a directory
Example:

## FileTime

Function FileTime( path$ )
Description: Get file time
Returns: The time the file at path was last modified
Example:

## FileSize

Function FileSize( path$ )
Description: Get file size
Returns: Size, in bytes, of the file at path, or -1 if the file does not exist
Example:

## FileMode

Function FileMode( path$ )
Description: Get file mode
Returns: file mode flags
Example:

## SetFileMode

Function SetFileMode( path$,mode )
Description: Set file mode
Example:

## CreateFile

Function CreateFile( path$ )
Description: Create a file
Returns: True if successful
Example:

## CreateDir

Function CreateDir( path$,recurse=False )
Description: Create a directory
Returns: True if successful
Information: If recurse is true, any required subdirectories are also created.
Example:

## DeleteFile

Function DeleteFile( path$ )
Description: Delete a file
Returns: True if successful
Example:

## RenameFile

Function RenameFile( oldpath$,newpath$ )
Description: Renames a file
Returns: True if successful

## CopyFile

Function CopyFile( src$,dst$ )
Description: Copy a file
Returns: True if successful

## CopyDir

Function CopyDir( src$,dst$ )
Description: Copy a directory
Returns: True if successful

## DeleteDir

Function DeleteDir( path$,recurse=False )
Description: Delete a directory
Returns: True if successful
Information: Set recurse to true to delete all subdirectories and files recursively - but be careful!
Example:

## ChangeDir

Function ChangeDir( path$ )
Description: Change current directory
Returns: True if successful
Example:

## ReadDir

Function ReadDir( path$ )
Description: Open a directory
Returns: An integer directory handle, or 0 if the directory does not exist
Example:

## NextFile

Function NextFile$( dir )
Description: Return next file in a directory
Returns: File name of next file in directory opened using ReadDir, or an empty string if there are no more files to read.

## CloseDir

Function CloseDir( dir )
Description: Close a directory

## LoadDir

Function LoadDir$( dir$,skip_dots=True )
Description: Load a directory
Returns: A string array containing contents of dir
Information: The skip_dots parameter, if true, removes the '.' (current) and '..' (parent) directories from the returned array.
Example:

## OpenFile

Function OpenFile:TStream( url:Object,readable=True,writeable=True )
Description: Open a file for input and/or output.
Information: This command is similar to the OpenStream command but will attempt to cache the contents of the file to ensure serial streams such as http: based url's are seekable. Use the CloseStream command when finished reading and or writing to a Stream returned by OpenFile.
Example:

## ReadFile

Function ReadFile:TStream( url:Object )
Description: Open a file for input.
Information: This command is similar to the ReadStream command but will attempt to cache the contents of the file to ensure serial streams such as http: based url's are seekable. Use the CloseStream command when finished reading and or writing to a Stream returned by OpenFile.
Example:

## WriteFile

Function WriteFile:TStream( url:Object )
Description: Open a file for output.
Information: This command is identical to the WriteStream command.
Example:

## CloseFile

Function CloseFile( stream:TStream )
Description: Closes a file stream.
Information: After performing file operations on an open file make sure to close the file stream with either CloseFile or the identical CloseStream command.