Search Tools Links Login

FileSystemObject Complete Ref.


Here a description about FSO(File System Object) and howto use it

Original Author: d1rtyw0rm

Code



Active X: Microsoft Scripting RunTime


FSO is there to help coder to work on file and directory.


The FSO model got 5 object

Drive - Folder - File - FileSystemObject - TextStream



Drive Object


Total Size : Disk Dimension


AvailableSizeFreeSpace : To get Free space of a disk


DriveLetter : Give the drive letter


DriveType : Give the type of a drive(fix,net,CD-Rom,etc...)


SerialNumber : give the serial number of a disk


FileSystem : NTFS,Fat,Fat32 etc.


IsReady : return True if drive is ready


VolumeName : ...



Exemple of use



Dim fso as new filesystemobject

dim d as drive

set d = fso.getdrive("c:") 'Creation of the drive object

msgbox d.totalsize

msgbox d.filesystem



Exemple of what the code will return 13gb, NTFS



FileSystemObject Object


CreateFolder : Create a directory


FolderExist : Return True if folder exist


GetParentFolder : Return parent name directory


Exemple of use



Dim fso as New FileSystemObject

fso.CreateFolder("C: estx")

msgbox fso.FolderExist("C: est")

msgbox fso.GetParentFolderName("C: estbb")



This example will first create the folder C: estx, after the first msgbox will return true cause we previously create the directory, the last msgbox will return 'C: est'.



Folder Object


Allows to manage the repertories


Delete : Delete a folder


Move : Move a folder


Copy : Copy a folder


Name : Name of the folder


Exemple of use



dim fso as new filesystemobject

dim r as folder

set r = fso.GetFolder("c:odsource")

msgbox r.name

r.copy "D:"

r.delete



First we create the folder object, the msgbox return "odsource", after it copy the folder on D: drive, and delete the folder on c:odsource.



File Object


Allows to obtain information on a file


Attributes : Return the file attribute (read only,hidden etc.)


Copy : Copy a file


DataCreated : Return creation date


DateLAstModified : Return date of the last modification


Delete : Delete a file


Drive : return the drive where the file is


Move :allow to move the file


Name : return the file name


ParentFolder : return the parent folder name of the file


Path : Return the full file path(include the file name)


ShortNAme : return the short name of the file


Size : File dimention


Type : return file type


Exemple of use


dim fsoas new FileSystemObject

Dim f as File


Set f = fso.GetFile
("c:d1rtyw0rmvisualbasicforum.com")

msgBox f.type

msgbox f.DateCreated

msgbox f.Path




The first msgbox return "COM", second "11-08-2002", third "C:d1rtyw0rmvisualbasicforum.com"



TextStream Object


Allow to manage a text file. Binary file cannot be managed by FSO.


Write : Write a text line without crlf


Write Line : Write a text line with crlf


WriteBlankLines : Write a number of crlf


Close : Close the file


Read : Reads a specific number of character


ReadLine : Read a complete line


ReadAll : Read complete file


Exemple of use


Dim fso As New FileSystemObject

Dim ts as TextStream

Dim s As String

'Creation of the text file'

Set ts = fso.OpenTextFile("C:vbfdirtyworm.txt", ForWriting,True)

ts.WriteLine "d1rtyw0rm rul'Z"

ts.Write "http:\www.d1rtyw"

ts.Write "0rm.ca.tc"

ts.BlankLines(4)

ts.WriteLine "odsource.com"

ts.Close


'Open for adding'


Set ts = fso.OpenTextFile("c:odsourcedirtyworm.txt",ForAppending)

ts.WriteLine "This line will be under odsource.com"

ts.close


'File Reading'


Set ts = fso.OpenTextFile("C:odsourcedirtyworm.txt", ForReading)

s = ts.Read(12)

MsgBox s 'Will print d1rtyw0rm ru'

s = ts.ReadLine 'Read the rest of the line'

s = ts.ReadAll


MsgBox s


ts.Close



-d1rtyw0rm

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 113 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.