Wiki Home

File System Object


Namespace: Wiki
File System Object is part of Windows Script Host (WSH). It offers a range of functions connected with files, folders and drives - see below for some examples. Athough much of its functionality is also available natively in VFP, it does have some capabilities that VFP doesn't support.

One of its benefits is the ability to read and write very large files. It is not subject to the 2 GB limit. I have successfully used it to read text files of around 8 GB, and to break these into smaller chunks for importing into VFP (see my article, "Working with large text files in Visual FoxPro" for more details).

As well as being able to work with larger files, it also seems to be faster than VFP's low-level file access functions. I haven't done any formal testing to verify that, but will report back after I've done so. Mike Lewis


I spoke too soon when I said File System Object (FSO) is faster than VFP's low-level file access functions. In most cases, it's not. It's also slower than high-level VFP commands such as APPEND FROM ... DELIMITED. A few simple timing tests can be seen here. Mike Lewis

Some examples from tek-tips.com

How to check for available space on a given disk drive.
objFSO = CreateObject('Scripting.FileSystemObject')
objDrive = objFSO.GetDrive('C:')
MESSAGEBOX('Available space: ' + chr(13)+TRANSFORM(objDrive.AvailableSpace,'999,999,999,999,999'+' kb' ))

How to copy a file
FSO = CreateObject('Scripting.FileSystemObject')
FSO.CopyFile('c:\COMPlusLog.txt','c:\x\')

How to create a folder
fso = createobject('Scripting.FileSystemObject')
fldr = fso.CreateFolder('C:\MyTest')

How to delete a folder
fso =createobject('Scripting.FileSystemObject')
fldr = fso.DeleteFolder('C:\MyTest')

How to determine if a folder exists.
fso =createobject('Scripting.FileSystemObject')
? fso.FolderExists('C:\MyTest')

How to create a file
fso = CreateObject('Scripting.FileSystemObject')
f1 = fso.CreateTextFile('c:\testfile.txt', .T.)

How to create a file and write to it.
fso = CreateObject('Scripting.FileSystemObject')
tf = fso.CreateTextFile('c:\testfile.txt', .t.)
tf.WriteLine('Testing 1, 2, 3.')
tf.WriteBlankLines(3) && Skip three lines
tf.Write ('This is a test.')
tf.CloseMODIFY FILE 'c:\testfile.txt'


yahia
( Topic last updated: 2013.05.24 09:48:52 AM )