FileSystem methods

From HashVB
Jump to: navigation, search

Description

Allows simple access to various file system functionality. It's use is similar to using the Command Prompt in Windows.

Members

ChDir

Changes the current directory. Similar to DOS's cd <dirname> command.

   Sub ChDir(Path As String)

ChDrive

Changes the current drive. Similar to typing a drive letter and colon in DOS.

   Sub ChDrive(Drive As String)

Dir

Returns name of file or directory matching the provided pattern and attribute (vbNormal is the default). If no match is found, then Dir returns vbNullString ("").

   Function Dir([PathName As String], [Attributes As VBFileAttribute = vbNormal]) As String

FileCopy

Copies a file. Requires two parameters. Can be used to rename or move a file when used in conjunction with Kill. Will throw an error if the destination path is not present. Always wise to use dir to check beforehand.

   Sub FileCopy(Source As String, Destination As String)

Kill

Deletes a file. Requires one parameter.

   Sub Kill(PathName As String) 



Examples

Renaming a file

   FileCopy "C:\Example.txt", "C:\Example.bkp"
   Kill "C:\Example.txt"

Moving a file

   If Dir("C:\sub", vbDirectory) = "" then MkDir ("C:\Sub")
   FileCopy "C:\Example.txt", "C:\sub\Example.bkp"
   Kill "C:\Example.txt"