October 1998: Processing a group of
files with a macro Often you will have a need to edit a large group of
files, making the same changes to each file. This can be very tedious, especially since
you have to open each file separately, make the changes, then save the file.
For example, if your company changes the formatting standard for all documents, or if
the name or address of the company changes, you could be forced to tediously open each
file created over the last several years, make the required changes, then save the file
with the changes.
The FileFind command, available in WPWin 7 and WPWin 8, lets
you process files as a batch, making the same changes to each file with a macro, thus
saving lots of time -- and your sanity.
I give two methods for using this command here. In the first method, we will do the
processing as we find each filename. In the second method, the filenames are assigned to
an array variable so that they can be used more than once during the course of the macro.
The method you choose to use will depend on the desired end result.
To simplify matters, all the files that require processing should be in the same
directory. It may also help if the filenames all have something in common, such as the
same filename extension, so that the macro can quickly find just the files you need to
work on.
Process each file as it is located
In the first method, we simply find a name, open and process the file, then save and
close the file. The filename is not saved or stored anywhere. We just get the work done
and move on:
Application(A1; "WordPerfect"; default; "US")
vFilename:=FileFind("c:\myfiles\*.wpd"; ;1)
FileOpen(vFilename)
// do the processing for that file here
FileSave()
CloseNoSave()
Repeat
vFilename:=FileFind(""; ;1)
FileOpen(vFilename)
// do the processing for that file here
FileSave()
CloseNoSave()
Until(vFilename="")
Each file that matches the specified mask will be opened, processed, then saved and
closed.
Assign filenames to an array
There may be times when you need to use the filenames again later, or for a purpose
other than opening and editing the files. You can use FileFind
to gather the names and assign them to an array. I've created a couple of functions, shown
below, to assign the filenames to an array:
In this example, the filenames are assigned to an array variable, and can be used
multiple times throughout the macro. For this particular macro, we just type the names out
on the screen, but you can add any processing you need instead.
Next month: Some of the new commands in WPWin 8

For more information on this topic, get a copy of my book.
My WPWin 8 macro book should be out some time in mid-October.
For information on ordering my book see my
web page.
Copyright Notice: The information included in the PerfectScript Journal is protected
by US Copyright. The author grants you the right to use the routines in your own macros as
needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No
representations are made regarding the fitness of this information for your
particular purpose, or for your ability or inability to use the information. You
are advised to make backups of all relevant files before implementing any suggestion
or technique.
© Copyright 1998 by J. Jeppson.