GUI – File handling

The executable offers a limited file handling capability.

For example: it does not explicitly have commands such as open / read / write / close. But thanks to its OLE capabilities this is easily overcome.

Default folder

Microsoft Windows has the concept of a default folder for certain file related activities. ( Technical detail: Windows APIs getcwd and chdir)

To get the current default folder use the dir command e.g.

message = dir

To set the current default folder use the dir = <string expression> e.g.

dir = "C:\Users\Public"

Now, one of the features/bugs of this executable is the handling of functions that only require one parameter.

Technically the keyword dir is overloaded, that is to say it can syntactically be used like a variable:

dim oldDir
oldDir = dir
dir = "C:\Users\Public"

And it can be used like a function:

 dir("z:\some path")

In both cases providing an invalid path will trigger an error.

If you want to avoid the error, consider something such as:

IF runon ( dir("z:\some path") ) then
  Message = "folder does not exist"
  Message = "folder exists"

runon suppresses error handling within an expression, and replaces it by a (inverse) boolean ( True = error occurred). See help ("runon")

Now, confusion can arise when entering a folder path, due to the use of the\ character in a string.

When reading in a string, the executable detects each \ and " and waits for the following character before deciding what to do. The handling is shown in the following table:

From To
\\ \
\" "
"" "

You might be used to Microsoft Visual Basic or Microsoft VBA which (I think) has a richer set of conversions, and (I think) requires that a single \ is always input as \\

This executable will treat the follow string definitions as creating the same result:

dir("z:\some path")
dir("z:\\some path")

Now, back to file related capabilities.

You can check whether a file system object (file or folder-path) exists using the isFile function. It takes a single string as input, and returns a value indicating whether the string represents a file/folder/invalid.

Return Value Meaning
  1 is a valid file
-1 is a valid folder
  0 is not in the file system

So the script snippet above (with runnon and dir ) could have been written as:

dim newFolder = "z:\some path"
IF ( isFile ( newFolder) == -1 ) THEN
dir( newFolder)
message = newfolder & " is not a valid folder name"

The commands mkDir and mkDirPath will create (make) a new folder.

  • mkDir will extend an existing folder path by one level,
  • mkDirPath will create a new folder path with multiple new levels.

(Technical detail: uses the Window APIs:  mkDir and SHCreateDirectory)

I do not provide a command to delete a folder. It makes me feel nervous, but if you need it then you can use OLE and the FileSystemObject, or use Dynamic Link Library (DLL) techniques to access the the Windows functions rmDir or _rmDir

This executable does have the ability to send a valid file to the recycling bin i.e. delete a file.

DeleteFile takes a single string parameter, the full path/filename of the file to be deleted, and returns True if successful, else false (0).