Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through a Dir to find a file

Status
Not open for further replies.

JONBOY74

Technical User
Sep 11, 2001
36
0
0
US
Can anyone help me

I want to loop through a number of files within a DIR and open the one that has todays date @ the end + .txt

Any Ideas

Jon
 
Check out the dir() function. Below is a dump from the Help Example. I've also executed a MS-DOS Dir command to get a list, then imported the list into a database table.
In terms of locating the file with today's date.. you can use the Instr() function to locate the "." then subtract the number of digits for the date. In the If condition of the loop, you can look for file names where mid(filename,Instr(...),x)... = Todays'date.. htwh...


' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> &quot;&quot; ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> &quot;.&quot; And MyName <> &quot;..&quot; Then
' Use bitwise comparison to make sure MyName is a directory.

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

Steve Medvid
&quot;IT Consultant & Web Master&quot;
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top