FileSystem Module

 <  Day Day Up  >  

The FileSystem module contains methods useful for interacting with the file system.

Compatibility

The FileSystem module contains methods that replace the file I/O statements ( Open , Close , Print , Write , Seek , etc.) that are no longer supported in Visual Basic .NET. Table A-1 gives the equivalent method for each statement. These methods are provided for backward compatibility use, and their general use is discouraged in favor of the methods in the System.IO namespace.


Many of the FileSystem methods take a file number as a parameter. File numbers can be any number between 1 and 255.

Warning

File numbers are shared across all threads of execution at runtime. Caution should be exercised when you are using file numbers in a multithreaded program.


 Public Sub ChDir(ByVal Path As String) 
Table A-1. FileSystem Equivalents

Visual Basic 6.0 Statement

FileSystem Method

Close

FileClose

Get

FileGet , FileGetObject

Input

Input , InputString

Line Input

LineInput

Lock

Lock

Open

FileOpen

Print

Print , PrintLine

Put

FilePut , FilePutObject

Seek

Seek

Spc

SPC

Tab

Tab

Unlock

Unlock

Width

FileWidth

Write

Write , WriteLine

The ChDir subroutine changes the current directory on the current drive.

 Public Sub ChDrive(ByVal Drive As Char) Public Sub ChDrive(ByVal Drive As String) 

The ChDrive subroutine changes the current drive.

 Public Function CurDir() As String Public Function CurDir(ByVal Drive As Char) As String 

The CurDir function returns the current directory for the specified drive, or the current drive if none is specified.

 Public Function Dir(ByVal Pathname As String, _   Optional ByVal Attributes As FileAttribute = FileAttribute.Normal) _   As String Public Function Dir() As String 

The Dir function allows iterating through all the files in a directory or volume, or all the files in the current directory. Calling the Dir function with a string starts the search. The Pathname parameter specifies the directory or volume to iterate; if no directory or volume name is given, the current directory is iterated. The directory or volume name can be followed by a file name to match. The file name can contain the wildcard characters ? (to match one character) and * (to match multiple characters). The Attributes parameter can further restrict the scope of the iteration. Once Dir has been called with a string, subsequent calls to the parameterless Dir will return the next file name in the specified location that matches the given file name.

 Public Function EOF(ByVal FileNumber As Integer) As Boolean 

The EOF function returns whether the end of the specified file has been reached.

 Public Function FileAttr(ByVal FileNumber As Integer) As OpenMode 

The FileAttr function returns the OpenMode used to open the specified file number.

 Public Sub FileClose(ByVal ParamArray FileNumbers() As Integer) 

The FileClose subroutine closes the specified file numbers.

 Public Sub FileCopy(ByVal Source As String, ByVal Destination As String) 

The FileCopy subroutine copies the Source file to the Destination directory.

 Public Function FileDateTime(ByVal PathName As String) As Date 

The FileDateTime function returns the date and time the specified file was created or last accessed.

 Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As ValueType, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Array, Optional ByVal RecordNumber As Long = -1, _   Optional ByVal ArrayIsDynamic As Boolean = False, _   Optional ByVal StringIsFixedLength As Boolean = False) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Boolean, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Byte, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Short, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Integer, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Long, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Char, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Single, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Double, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Decimal, Optional ByVal RecordNumber As Long = -1) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As String, Optional ByVal RecordNumber As Long = -1, _   Optional ByVal StringIsFixedLength As Boolean = False) Public Sub FileGet(ByVal FileNumber As Integer, _   ByRef Value As Date, Optional ByVal RecordNumber As Long = -1) 

The FileGet function reads a value of the specified type from the given file number. The RecordNumber parameter specifies the record to use for files that were opened for Random access. The ArrayIsDynamic parameter specifies whether the array being read was stored as a dynamic array using FilePut . The StringIsFixedLength specifies whether the string (or array of strings) being read was stored as fixed-length strings using FilePut .

 Public Sub FileGetObject(ByVal FileNumber As Integer, _   ByRef Value As Object, Optional ByVal RecordNumber As Long = -1) 

The FileGetObject function reads a value whose type is unknown from the given file number. The RecordNumber parameter specifies the record to use for files that were opened for Random access.

 Public Function FileLen(ByVal PathName As String) As Long 

The FileLen function returns the length of the specified file in bytes.

 Public Sub FileOpen(ByVal FileNumber As Integer, _   ByVal FileName As String, ByVal Mode As OpenMode, _   Optional ByVal Access As OpenAccess = OpenAccess.Default, _   Optional ByVal Share As OpenShare = OpenShare.Default, _   Optional ByVal RecordLength As Integer = -1) 

The FileOpen function opens a file for input or output. The Mode , Access , and Share parameters specify the type of operations that will be performed on the file. If the open mode is OpenMode.Binary , the RecordLength parameter specifies the size of buffer used to read from the file. If the open mode is OpenMode.Random , the RecordLength parameter specifies the size of a single record in the file.

 Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As ValueType, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Array, Optional ByVal RecordNumber As Long = -1, _   Optional ByVal ArrayIsDynamic As Boolean = False, _   Optional ByVal StringIsFixedLength As Boolean = False) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Boolean, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Byte, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Short, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Integer, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Long, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Char, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Single, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Double, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Decimal, Optional ByVal RecordNumber As Long = -1) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As String, Optional ByVal RecordNumber As Long = -1, _   Optional ByVal StringIsFixedLength As Boolean = False) Public Sub FilePut(ByVal FileNumber As Integer, _   ByVal Value As Date, Optional ByVal RecordNumber As Long = -1) 

The FilePut function writes a value of the specified type to the given file number. The RecordNumber parameter specifies the record to use for files that were opened for Random access. The ArrayIsDynamic parameter specifies whether the array being written should be stored with a dynamic array header. The StringIsFixedLength specifies whether the string (or array of strings) being written should be stored with a fixed-length string header.

 Public Sub FilePutObject(ByVal FileNumber As Integer, _   ByVal Value As Object, Optional ByVal RecordNumber As Long = -1) 

The FilePutObject function writes a value, whose type is unknown, to the given file number. The RecordNumber parameter specifies the record to use for files that were opened for Random access.

 Public Sub FileWidth(ByVal FileNumber As Integer, _   ByVal RecordWidth As Integer) 

The FileWidth subroutine assigns an output line length to a given file number. The line length determines how many characters will be output before a new line is started. A line length of zero indicates that a line has no limit.

 Public Function FreeFile() As Integer 

The FreeFile function returns the next file number that is not currently in use.

 Public Function GetAttr(ByVal PathName As String) As FileAttribute 

The GetAttr function returns the attributes of the given file or directory.

 Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Object) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Boolean) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Byte) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Short) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Integer) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Long) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Char) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Single) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Double) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Decimal) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As String) Public Sub Input(ByVal FileNumber As Integer, ByRef Value As Date) 

The Input function reads a value from a given file number.

 Public Function InputString(ByVal FileNumber As Integer, _   ByVal CharCount As Integer) As String 

The Input function reads up to CharCount number of characters from the given file number.

 Public Sub Kill(ByVal PathName As String) 

The Kill subroutine deletes the specified file.

 Public Function LineInput(ByVal FileNumber As Integer) As String 

The LineInput function reads a string from a given file number.

 Public Function Loc(ByVal FileNumber As Integer) As Long 

The Loc function returns the current position in the specified file number.

 Public Sub Lock(ByVal FileNumber As Integer) Public Sub Lock(ByVal FileNumber As Integer, ByVal Record As Long) Public Sub Lock(ByVal FileNumber As Integer, _   ByVal FromRecord As Long, ByVal ToRecord As Long) 

The Lock function prevents other processes from accessing all or part of the specified file number.

 Public Function LOF(ByVal FileNumber As Integer) As Long 

The LOF function returns the length, in bytes, of the specified file number.

 Public Sub MkDir(ByVal Path As String) 

The MkDir subroutine creates a new directory.

 Public Sub Print(ByVal FileNumber As Integer, _   ByVal ParamArray Output() As Object) 

The Print subroutine outputs the information to the specified file number in a display-formatted manner.

 Public Sub PrintLine(ByVal FileNumber As Integer, _   ByVal ParamArray Output() As Object) 

The PrintLine subroutine outputs the information to the specified file number in a display-formatted manner, followed by a line feed.

 Public Sub Rename(ByVal OldPath As String, ByVal NewPath As String) 

The Rename subroutine renames a file or directory.

 Public Sub Reset() 

The Reset subroutine closes all open file numbers.

 Public Sub RmDir(ByVal Path As String) 

The RmDir subroutine deletes a directory.

 Public Sub Seek(ByVal FileNumber As Integer, ByVal Position As Long) Public Function Seek(ByVal FileNumber As Integer) As Long 

The Seek function returns the current position of the specified file number. The Seek subroutine sets the current position for the specified file number.

 Public Sub SetAttr(ByVal PathName As String, _   ByVal Attributes As FileAttribute) 

The SetAttr subroutine sets the file attributes for the specified file or directory.

 Public Function SPC(ByVal Count As Short) As SpcInfo 

The SPC function is used with the Print and PrintLine subroutines to output a specified number of spaces in the output.

 Public Function TAB() As TabInfo Public Function TAB(ByVal Column As Short) As TabInfo 

The TAB function is used with the Print and PrintLine subroutines to output one or more tab spaces in the output.

 Public Sub Unlock(ByVal FileNumber As Integer) Public Sub Unlock(ByVal FileNumber As Integer, ByVal Record As Long) Public Sub Unlock(ByVal FileNumber As Integer, _   ByVal FromRecord As Long, ByVal ToRecord As Long) 

The Unlock subroutine allows other processes to access some or all of the specified file number. An Unlock call must exactly match a previous Lock call.

 Public Sub Write(ByVal FileNumber As Integer, _   ByVal ParamArray Output() As Object) 

The Write subroutine outputs the information to the specified file number.

 Public Sub WriteLine(ByVal FileNumber As Integer, _   ByVal ParamArray Output() As Object) 

The WriteLine subroutine outputs the information to the specified file number followed by a line feed.

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net