Ask the MultiValued Visual
Basic Expert - #12A
(as published in Spectrum
magazine Nov/Dec 1998)
To email your questions to "Ask the MultiValued VB
Expert", click here.
Copyright © 1996-98 Caduceus Consulting. All rights reserved.

SELECT and READNEXT Windows Files
Dear
MV/VB Expert:
What
is an easy way to do a function that you would do to ONE file
(say: renaming it), but to do it to ALL files on a drive without
having to click on each file. I have read four or five VB4 and
VB5 books and have never seen code that relates to this. - R.
Shepheard, Relte Corporation
I
believe what you are looking for is the equivalent of a SELECT
statement performed on a Windows directory in order to work with
a group of files, using some type of READNEXT operation. Yes,
this is possible in Visual Basic!
The Dir
function returns the name of a file or directory that matches a
specified pattern and/or file attribute. It is called as:
FirstFName
= Dir(PathPattern$ {, Attributes%})
Note
that the pathname pattern can contain wildcards such as
"*" and "?", and 'attributes' refers to a sum
of Windows file attributes: Normal (0), Hidden (2), System (4),
Volume Label (8), and Directory (16).
The
first time you call it, the Dir function returns the first
matching filename. To get any additional filenames that match the
path pattern, call Dir again with no arguments. A zero-length
string tells you that there are no more matching files. And just
like a SELECT, files are found in no particular order. Of course,
if it's renaming you want to do, take care: the same file may
show up under the old and new names!

To email your questions to "Ask the MultiValued VB
Expert", click here.
Copyright © 1996-98 Caduceus Consulting. All rights reserved.
Added: August 21, 1998.
Return to Caduceus
Consulting Home Page