WINAPI Filehandling
by Wil van Antwerpen
Summary
With this package (vwin32fh.pkg) you can copy, move, delete or rename any file, select a folder, test if a folder exists, create a new folder, delete an existing folder, start a program by its registered name, test if a file exists and more... all in the windows-environment. |
Size: 45 KB |
Download |
Date Created: |
31/10/1999 |
Date Updated: |
08/08/2023 |
Author: |
Wil van Antwerpen
|
Company: |
Antwise Solutions |
Windows Filehandling
The vWin32fh package is a wrapper for standard windows API calls used for file handling.
The download includes a small example program that shows you how-to use some of these functions.
The wrapperfunctions declared in this package all support long file and foldernames.
.
Supported methods
Function vSelect_File Global String sSupportedFileTypes String sCaptionText String sInitial_Folder Returns String
This function opens the Windows standard file open dialog and returns the selected file_name. Returns '' if the user didn't make a selection.
Procedure vDDE_Error_Handler Integer iErrorID (obsolete)
This method shows the error message for the passed DDE Error ID.
Please use the DDE_Error_To_String function instead
Function DDE_Error_To_String Integer iErrorID Returns String
This function returns error message for the passed DDE Error ID.
Function vFolderExists Global String sFolderName returns Integer
Does the directory exist? - No= 0, Yes= 1
This also works with UNC path encoding and wildcards
Function vSHBrowseForFolder Global String sDialogTitle returns String
returns folder name if a folder was selected, otherwise returns ""
Function vCreateDirectory Global String sNewFolder Returns Integer
returns:
- 0 if the folder is created.
- 1 if the API-call returned an error.
Function vRemoveDirectory Global String sFolder Returns Integer
With this function one can remove a directory.
returns:
- 0 if the folder is removed.
- 1 if the API-call returned an error (Use GetLastE
- 2 if the folder did not exist
- 3 if the sFolder parameter passed is equal to ""
Function vVerifyNewFolder Global String sFolderName Returns Integer
This function informs the user that he entered a yet unknown folder and asks if he/she wants to create the folder (Yes/No)
Choice: "Yes" - this creates the folder, if successful, the function returns false else it will be true.
Choice: "No" - returns TRUE, This allows the programmer to take action, for example: to stop a save
Precondition: A foldername must be entered. We do not check for empty paths
This function returns a non-zero value if the folder isn't created afterwards
Procedure vShellExecute global String sOperation String sDocument String sParameters String sPath
This will perform an operation on a file (e.g. open) with the application registered in the Windows Registry to open that type of file (via its extension) sOperation would be "OPEN" (it could also be "PRINT" etc).
Function vDeleteFile Global String sFileName Returns Integer
Uses WinAPI to delete the file with sFileName.
Returns a nonzero value if the operation failed.
Function vCopyFile Global String sSource String sDestination returns Integer
Uses WinAPI to copy the file sSource to the folder in sDestination.
Returns a nonzero value if the operation failed.
Function vMoveFile Global String sSource String sDestination returns Integer
Uses WinAPI to move the file sSource to the folder in sDestination.
Returns a nonzero value if the operation failed.
Function vRenameFile Global String sSource String sDestination returns Integer
Uses WinAPI to rename the file or folder sSource into sDestination.
Returns a nonzero value if the operation failed.
Function vGetWindowsDirectory Returns String
Returns the name of the folder where windows is installed.
Function vMakeTempFile Returns String
This function creates a temporary file. It will first try to create this in the normal temp-folder.
If that one doesn't exist the tempfile is created in the current folder.
The file is always prefixed with "tmp" and if succesful will return the name of the created file.
In the case of errors, an empty string is returned.
Function vCreateTempFileInPath String Path String Prefix Returns String
Function vConvertFileDateTime Global Dword dwLowDateTime Dword dwHighDateTime Returns String
This function can be used to convert WinAPI file datetimes into a string that returns the date/time in a readable fashion.
Function vFilePathExists String sFilePathMask Returns Integer
A windows replacement for the standard function FileExists.
This version will also return (true) for a file when it is open by an application.
Note that you can apply normal windows mask-signs in the filename such as * and ?
Example: Get vFilePathExists "C:\config.sy?"
This will return true if you have a file matching these conditions. (aka config.sys)
Function vFolderFormat Global String sFolderName Returns String
Formats a foldername by first trimming it and after that by sticking a directory separator (/\) to the end if it doesn't have one there already.
The folder may contain a drive letter or UNC encoding.
Download
vwin32fh-20230808.zip DataFlex 23.0 support, moved including windows pkg file into windows only, not webapp area.
vwin32fh-20211125.zip This fixes a few struct alignment issues for 64 bit support.
vwin32fh-20210916.zip Unicode & 64 bit support for DataFlex 20, minimum version DF19.0, unicode fixes for vGetWindowsDirectory and vGetTempPath, better error handling, fixed DF19.0 support.
vwin32fh-20210516.zip Unicode & 64 bit support for DataFlex 20, minimum version DF19.1
vwin32fh-20180716.zip Changed conditional compile logic around zerostring to use compiler version. The reason being that DF19.1 and higher always should use DAWs version and not our workaround. Removed DF18.0 and earlier support.
vwin32fh-20180708.zip Fix warnings from Starzen's excellent code parser project.
vwin32fh-20180618.zip The zerostring function wasn't introduced in DF19.0, but in DF19.1 and thus my redeclaration failed on DF19.0.
vwin32fh-20180614.zip DF19.1 update broke Function vFolderFileCount due to a missing UCharArrayToString function call.
vwin32fh-20180606.zip Fix warnings for DataFlex 19.1, using more modern code, consider this version BETA
vwin32fh-20180404.zip Fix typos in define TIME_NOMIHUTESORSECONDS and DATE_SHORTDATE, Thanks Vincent for the report! <- Last version for DataFlex 18.0 and earlier!
vwin32fh-20171031.zip fix vParentPath if parent subfolder also occurs in earlier part of path, add vPathIsDirectory
vwin32fh-20170905.zip fix parsefoldername if filename part also part of path
vwin32fh-20170411.zip Lot's of patches, DF19.0 support, it is now a library
vWin32fh package March 13 2007 20Kb fixed parsefoldername bug, added vParentPath function, vSelectSaveFile function
vWin32fh package March 10 2006 19Kb added a bunch of new CSIDL types
vWin32fh package feb 28 2005 16Kb
vWin32fh package (original) ~14kb zipfile
Subversion
http://svn.vdf-guidance.com/vwin32fh/trunk/
Project Page
http://projects.vdf-guidance.com/projects/vwin32fh-windows-file-handling
Addendum
If you want to use the demo application under VDF8/VDF9 then please make the following changes:
Insert the following (or a ws of your choice) in the demo src
replace
use dfpanel
use dfbase
with
use globalallent
use DFAbout
#REPLACE CURRENT$WORKSPACE "yourworkspace.co"
Register_Object Client_Area
1) use package for application workspace
Use cApplication.pkg
2) Set date attributes as needed
Set_Date_Attribute sysdate4_State to dftrue
Set_Date_Attribute Date4_State to dftrue
Set_Date_Attribute epoch_value to 60
3) Application Workspace - help type and name
Object oApplication is a cApplication
Procedure OnCreate
Send DoOpenWorkspace CURRENT$WORKSPACE
End_Procedure
Set peHelpType to htHtmlHelp
Set psHelpFile to 'KFPhelp.chm'
Set pbEnterKeyAsTabKey to True
Set psCompany to "Kirk Freeport"
Set psProduct to "Kirknet"
Set psVersion to "1.0"
Set psProgram to (Module_Name(Self))
End_Object // oApplication
Thanks to Dave Robinson for these notes.
|