OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Files and Directories<br />
Note – VBA : The options provided in VBA for searching through directories specifically for files with the<br />
concealed, system file, archived, and volume name properties does not exist in <strong>OpenOffice</strong>.<strong>org</strong> Basic<br />
because the corresponding file system functions are not available on all operating systems.<br />
Note – VBA : The path specifications listed in Dir may use the * and ? place holders in both VBA and<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic. In <strong>OpenOffice</strong>.<strong>org</strong> Basic, the * place holder may however only be the last character of a<br />
file name and/or file extension, which is not the case in VBA.<br />
Creating and Deleting Directories<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic provides the MkDir function for creating directories.<br />
MkDir ("C:\SubDir1")<br />
This function creates directories and sub-directories. All directories needed within a hierarchy are also created, if<br />
required. For example, if only the C:\SubDir1 directory exists, then a call<br />
MkDir ("C:\SubDir1\SubDir2\SubDir3\")<br />
creates both the C:\SubDir1\SubDir2 directory and the C:\SubDir1\SubDir2\SubDir3 directory.<br />
The RmDir function deletes directories.<br />
RmDir ("C:\SubDir1\SubDir2\SubDir3\")<br />
If the directory contains sub-directories or files, these are also deleted. You should therefore be careful when<br />
using RmDir.<br />
Note – VBA : In VBA, the MkDir and RmDir functions only relate to the current directory. In <strong>OpenOffice</strong>.<strong>org</strong><br />
Basic on the other hand, MkDir and RmDir can be used to create or delete levels of directories.<br />
Note – VBA : In VBA, RmDir produces an error message if a directory contains a file. In <strong>OpenOffice</strong>.<strong>org</strong><br />
Basic, the directory and all its files are deleted. If you use the CompatibilityMode ( true ) function,<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic will behave like VBA.<br />
Copying, Renaming, Deleting and Checking the<br />
Existence of Files<br />
The following call creates a copy of the Source file under the name of Destination:<br />
FileCopy(Source, Destination)<br />
With the help of the following function you can rename the OldName file with NewName. The As keyword syntax,<br />
and the fact that a comma is not used, goes back to the roots of the Basic language.<br />
Name OldName As NewName<br />
The following call deletes the Filename file. If you want to delete directory (including its files) use the RmDir<br />
function.<br />
Kill(Filename)<br />
The FileExists function can be used to check whether a file exists:<br />
If FileExists(Filename) Then<br />
MsgBox "file exists."<br />
End If<br />
44 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010