Code for picking out file names in directory listing

  • Thread starter Thread starter Sandy
  • Start date Start date
S

Sandy

I have a list of files that I need to search through and
only do a routine on file names starting with "abc"

So, I have :
Drive\SomeDirectory\SomeOtherDirectory\xxxxOne.xls
Drive\SomeDirectory\SomeOtherDirectory\xxxxTwo.xls
Drive\SomeDirectory\SomeOtherDirectory\abcAFile.xls
Drive\SomeDirectory\SomeOtherDirectory\xxxxThree.xls
Drive\SomeDirectory\SomeOtherDirectory\abcAnotherFile.xls

I need code for skipping all files with "abc" in them.

If anyone has an answer, can you be as specific as
possible? I'm having an extremely rough time with this
one!

Sandy
 
Dim strFile As String
strFile = Dir("Drive\SomeDirectory\SomeOtherDirectory\abc*.xls")
Do While strFile <> ""
' code here for what to do with the file that starts with "abc"
' ...
' ...
' get next file that starts with "abc"
strFile = Dir()
Loop
 
Hello,
think you mean something like:

Dim strFile As String
strFile = Dir("Drive\SomeDirectory\SomeOtherDirectory\*.xls")
Do While strFile <> ""
if lcase$(left$(strFile,3))="abc" then
'abc's
else
'Others
endif
strFile = Dir()
Loop

Heiko
:-)
 
Ken -

Thanks for your response!

Sandy
-----Original Message-----
Dim strFile As String
strFile = Dir ("Drive\SomeDirectory\SomeOtherDirectory\abc*.xls")
Do While strFile <> ""
' code here for what to do with the file that starts with "abc"
' ...
' ...
' get next file that starts with "abc"
strFile = Dir()
Loop

--
Ken Snell
<MS ACCESS MVP>




.
 
Hello Sandy
The $ is to ensure working with strings rather than with variant
datatypes.
Heiko
:-)
 
Back
Top