In your script, you have a line:
FileName = Dir(CurrDir & "*.*", vbDirectory)
This basically creates a "collection" of information from "CurrDir".
vbDirectory indicates that it is to return "directories or folders in addition 
to files with no attributes".
 
the statement itself returns the first entry in CurrDir.
 
to loop through the rest of the entries in Currdir,
you use Dir()
So basically, Filename = Dir(CurrDir & "*.*",vbDirectory)
gets the first entry,
Filename = Dir() 
loops through the rest of the entries.
 
BTW:  All this can be found using the VBA "help".
 
hope this helps.

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------


>________________________________
> From: maksood alam <786maks...@gmail.com>
>To: excel-macros@googlegroups.com 
>Sent: Wednesday, December 4, 2013 2:05 PM
>Subject: $$Excel-Macros$$ Please help on FileName = Dir()
>  
>
>
>Hi Guys, 
>
>Can anyone please explaint what  FileName = Dir() is doing in below code. 
>
>
>Public Sub RecursiveDir(ByVal CurrDir As String, Optional ByVal Level As Long)
>Dim Dirs() As String
>Dim NumDirs As Long
>Dim FileName As String
>Dim PathAndName As String
>Dim i As Long
>Dim Filesize As Double
>' Make sure path ends in backslash
>If Right(CurrDir, 1) <> "\" Then CurrDir = CurrDir & "\"
>' Put column headings on active sheet
>Cells(1, 1) = "Path"""
>Cells(1, 2) = "Filename"""
>Cells(1, 3) = "Size"""
>Cells(1, 4) = "Date / Time"""
>Range("A1:D1").Font.Bold = True
>' Get files
>FileName = Dir(CurrDir & "*.*", vbDirectory)
>Do While Len(FileName) <> 0
>If Left(FileName, 1) <> "." Then 'Current Dir
>    PathAndName = CurrDir & FileName
>    MsgBox (GetAttr(PathAndName) And vbDirectory)
>        If (GetAttr(PathAndName) And vbDirectory) = vbDirectory Then
>'store found directories
>            ReDim Preserve Dirs(0 To NumDirs) As String
>            Dirs(NumDirs) = PathAndName
>            NumDirs = NumDirs + 1
>        Else
>'Write the path and file to the sheet
>        Cells(WorksheetFunction.CountA(Range("A:A")) + 1, 1) = _
>        CurrDir
>        Cells(WorksheetFunction.CountA(Range("B:B")) + 1, 2) = _
>        FileName
>'adjust for filesize > 2 gigabytes
>       Filesize = FileLen(PathAndName)
>            If Filesize < 0 Then Filesize = Filesize + 4294967296#
>                Cells(WorksheetFunction.CountA(Range("C:C")) + 1, 3) = Filesize
>                Cells(WorksheetFunction.CountA(Range("D:D")) + 1, 4) = _
>                FileDateTime(PathAndName)
>            End If
>        End If
>FileName = Dir()
>Loop
>' Process the found directories, recursively
>For i = 0 To NumDirs - 1
>RecursiveDir Dirs(i), Level + 2
>Next i
>End Sub 
>
>
>
>
>Thanks, 
>Maksood Alam
-- 
>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>https://www.facebook.com/discussexcel
> 
>FORUM RULES
> 
>1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
>Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
>quick attention or may not be answered.
>2) Don't post a question in the thread of another member.
>3) Don't post questions regarding breaking or bypassing any security measure.
>4) Acknowledge the responses you receive, good or bad.
>5) Jobs posting is not allowed.
>6) Sharing copyrighted material and their links is not allowed.
> 
>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>members are not responsible for any loss.
>--- 
>You received this message because you are subscribed to the Google Groups "MS 
>EXCEL AND VBA MACROS" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to excel-macros+unsubscr...@googlegroups.com.
>To post to this group, send email to excel-macros@googlegroups.com.
>Visit this group at http://groups.google.com/group/excel-macros.
>For more options, visit https://groups.google.com/groups/opt_out.
>
>
>    

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to