Difference between revisions of "FileSystem methods"

From HashVB
Jump to: navigation, search
m (File system functions moved to FileSystem methods: Inaccurate name. Not all members are functions.)
(No difference)

Latest revision as of 17:00, 11 May 2009


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



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

   Sub ChDir(Path As String)


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

   Sub ChDrive(Drive As String)


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


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)


Deletes a file. Requires one parameter.

   Sub Kill(PathName As String) 


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"