VDF-GUIdance logo



  Visual DataFlex Logo
  

Shared knowledge leads to accumulated knowledge

        Printer Friendly Page


FileSystem class

by Allan Greis Eriksen

Summary

A replacement for the akefs - binary file access - package.

This is a class with methods to access binary files. Features common operations like copy, delete, move, rename, filesize, date, icon, search, create directory, remove directory, list files and much more.

- The number of files to open are only limited by system resources (so not the 10 open file limit as with the native direct_output/direct_input commands)
- There is no 2GB filesize limit, the filesize limit is 9 exabyte

This class is written for VDF15 and up.
Size: 72 KB Download
Date Created: 14/09/2009
Date Updated: 16/05/2021
Author: Allan Greis Eriksen
Company: NOVAX A/S


cFileSystem Class


Introduction


This class is a redesign of the akefs.pkg package that I made many years ago for Visual DataFlex 5 and up. This is still available at https://www.vdf-guidance.com but it is using some very old technique and all methods are global. It also makes use of some global variables. Not very object oriented, so I decided to make a class of it all.

The cFilesystem class is based on a cObject class and makes use of the new native array and struct options. It also uses the variable type BigInt for file sizes. Therefore it is necessary to use a recent version of Visual DataFlex. I made this class with Visual DataFlex 15.0 but it should be possible to use the class down to Visual DataFlex 11.0.

This class also breaks the 2GB file limit that the old akefs.pkg has. Now you can use this class to handle huge files in theory up to 9 EB (etabyte) files!

Another design goal was to speed up the file access and the transfer of data between methods. You will notice that some of the methods will take parameters by reference instead of by value. Further more you can now subclass and argument the methods for your own need.

During the rewrite I killed to methods called RecursiveRemoveDirectory and RecursiveCopyDirectory. The purpose of these functions was to remove or copy a directory with all its children. While they worked okay, the where somewhat slow in the process. If you still need this functionality I recommend using the shell methods with vWin32fh.pkg by Wil van Antwerpen.

This class is open source and you may use it in commercial or non-commercial software free of charge. For more information, see VDF GUIdance Open License Statement.

Help file



The class comes with a CHM help file and all methods have been carefully documented and come with examples in the help file. You are strongly encouraged to check the helpfile when looking for answers.

Here's the content of the introduction page of that help file to give you an idea:
The cFilesystem class is a collection of functions to access files and directories through windows kernel API.

This help file is divided into three sections.

  • Properties
  • Binary file access
  • File and directory access
This class is not limited to handle file sizes of 2 GB but can handle huge files sizes. You can also have as many open file connections as you like. Also you can get a status for each of the file and directory operations to tell if the operation was successful. This is just some of the benefits you gain when using this class.

All filenames used in this class is in OEM format. Any method that return filenames are also in OEM format. You do not have to worry about converting filenames into ANSI format to be able to access filenames with international characters. This is all taking care of by the cFilesystem class.

There are also some helper methods included. These are used by other parts of cFilesystem you can use them to if you find them useful.

Example of use:

You may want to create an object of this class in your .src file like this:
Use cFilesystem.pkg

Object oFilesystem is a cFilesystem
End_Object

This ensures that you have easy access to the filesystem object from all over your application. But this is not a requirement. You can easily create an object of the cFilesystem class i.e. in a view where it is needed.

In the example code for the rest of this help file it is assumed that there is an object called oFilesystem of the cFilesystem class instantiated earlier in the application like the example above.

Download



2021-05-16 cFileSystem.zip ~ 72kB

2019-09-14 cFileSystem.zip ~ 72kB

2018-09-04 cFileSystem.zip ~ 70kB

2015-08-11 cFileSystem.zip ~ 69kB

2015-07-01 cFileSystem.zip ~ 66kB

2012-01-13 cFileSystem.zip ~ 61kB

2010-08-11 cFileSystem.zip ~ 61kB

List of Changes



2021/05/16


Added Unicode & 64 bit support for DataFlex 20
Supported from DataFlex 19.1 and higher
  • Function FileSize is now obsolete, use Function FileSizeEx instead. This is because of a name clash with a native DataFlex package and being able to support > 2GB in file sizes.

2019/09/14


Fixed warnings that showed up in DataFlex 19.1 and code cleanup.
Supported from DataFlex 19.1 and higher.

2018/09/04


This is now a library and supported from DataFlex 18.1 and higher.
Added new method Set/Get FileLastWriteTime

2015/08/11


This one has added a function called FileVersion. This will give you the file version information from the specified file. Information like Company name, File description, Product version and information like the file contains debug information, if it is designed for 32 bit windows or DOS, the file contains a font and loads more.
Check out the VS_FIXEDFILEINFO structure from MSDN for more info

2015/07/21


Added a Buffer to reading a binary files.

Added BinaryFileReadCachedUntilMatch, BinaryFileReadCachedCSV and BinaryFileReadCachedLN that reads using the buffer.

Added BinaryFileCachedPosition that can be set and get.

BinaryFileEndOfFile added that returns if the last read from the binary file had reached the end.

FileExtention function that returns the file extention.

FileSearchRecursive function added to search in subdirectories.

Changed the filename conversion in FileSearch so it is done faster.

RemoveExtention function added that removes/split the file extention from a filename.

Fixed missing errornumber fix as reported in Error in error reporting forum post.

Help.chm - Small changes in documentation for BinaryFileRead and BinaryFileWrite.