Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dir function resetting

I am trying to use the Dir function to loop through folders in specified
directories, and again to loop through the files in those folders, but my
second Dir is messing with the first one (€œRecFile = Dir€ in inner loop makes
€œFolder=Dir€ in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

€˜insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dir function resetting

You could use your current procedure to go 1 level of folders deep. Is that
what you want or do you want to examine all folders below the specified
folder, no matter the depth?

--
Regards,
Tom Ogilvy

"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in specified
directories, and again to loop through the files in those folders, but my
second Dir is messing with the first one ("RecFile = Dir" in inner loop

makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory

Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dir function resetting

See this article for multiple methods. 2nd method is using DIR

http://support.microsoft.com/kb/185476/EN-US/
How To Search Directories to Find or List Files

http://support.microsoft.com/kb/185601/EN-US/
HOW TO: Recursively Search Directories by Using FileSystemObject

http://support.microsoft.com/kb/186118/EN-US/
How To Use FileSystemObject with Visual Basic

--
Regards,
Tom Ogilvy



"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in specified
directories, and again to loop through the files in those folders, but my
second Dir is messing with the first one ("RecFile = Dir" in inner loop

makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory

Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dir function resetting

Maybe I'm missing something, but wouldn't I have to specify each of the
folder names? I have sixty of them (12 each in 5 directories), and don't
want to list them all in the code, if possible.

"Don Guillett" wrote:

try to modify this idea to suit

Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\yourfolder\*.mp3"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub

--
Don Guillett
SalesAid Software

"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in specified
directories, and again to loop through the files in those folders, but my
second Dir is messing with the first one ("RecFile = Dir" in inner loop

makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory

Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dir function resetting

Yes, I only need to go one level deep within each of the directories - each
of the 5 directories has 12 folders within it (for months of the year), and I
would only need the files within there. There should not be any folders
within the monthly folders, just files.

"Tom Ogilvy" wrote:

You could use your current procedure to go 1 level of folders deep. Is that
what you want or do you want to examine all folders below the specified
folder, no matter the depth?

--
Regards,
Tom Ogilvy

"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in specified
directories, and again to loop through the files in those folders, but my
second Dir is messing with the first one ("RecFile = Dir" in inner loop

makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory

Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dir function resetting

Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
dim v(1 to 12) as String
dim i as Long
i = 1
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory Then
v(i) = Folder
i = i + 1
End if
Folder = Dir()
Loop

for i = 1 to 12
Folder = v(i)
if len(trim(folder)) < then
RecFile = Dir(FolderPath & Folder & "\*-pt.xls")
Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop
End If

Next
End Sub

--
Regards,
Tom Ogilvy


"Emily Edgington" wrote in
message ...
Yes, I only need to go one level deep within each of the directories -

each
of the 5 directories has 12 folders within it (for months of the year),

and I
would only need the files within there. There should not be any folders
within the monthly folders, just files.

"Tom Ogilvy" wrote:

You could use your current procedure to go 1 level of folders deep. Is

that
what you want or do you want to examine all folders below the specified
folder, no matter the depth?

--
Regards,
Tom Ogilvy

"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in

specified
directories, and again to loop through the files in those folders, but

my
second Dir is messing with the first one ("RecFile = Dir" in inner

loop
makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling

it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) =

vbDirectory
Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dir function resetting

Awesome! This is exactly what I needed!

"Tom Ogilvy" wrote:

Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
dim v(1 to 12) as String
dim i as Long
i = 1
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) = vbDirectory Then
v(i) = Folder
i = i + 1
End if
Folder = Dir()
Loop

for i = 1 to 12
Folder = v(i)
if len(trim(folder)) < then
RecFile = Dir(FolderPath & Folder & "\*-pt.xls")
Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop
End If

Next
End Sub

--
Regards,
Tom Ogilvy


"Emily Edgington" wrote in
message ...
Yes, I only need to go one level deep within each of the directories -

each
of the 5 directories has 12 folders within it (for months of the year),

and I
would only need the files within there. There should not be any folders
within the monthly folders, just files.

"Tom Ogilvy" wrote:

You could use your current procedure to go 1 level of folders deep. Is

that
what you want or do you want to examine all folders below the specified
folder, no matter the depth?

--
Regards,
Tom Ogilvy

"Emily Edgington" wrote in
message ...
I am trying to use the Dir function to loop through folders in

specified
directories, and again to loop through the files in those folders, but

my
second Dir is messing with the first one ("RecFile = Dir" in inner

loop
makes
"Folder=Dir" in outer loop no longer work).

I have tried putting the inner loop in it's own procedure and calling

it
within the outer loop, to no avail. Any suggestions?



Dim FolderPath As String
Dim Folder As String
Dim RecFile As String

Public Sub Create_File_List()
Folder = Dir(FolderPath, vbDirectory)
Do While Folder < ""
If Folder < "." And Folder < ".." Then
If (GetAttr(FolderPath & Folder) And vbDirectory) =

vbDirectory
Then

RecFile = Dir(FolderPath & Folder & "\*-pt.xls")

Do Until RecFile = ""

'insert some formulas, yadda yadda yadda

RecFile = Dir

Loop

End If
End If
Folder = Dir
Loop

End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are my options resetting themselves? cbare Excel Discussion (Misc queries) 0 November 2nd 06 11:30 PM
Resetting the Filter Function .. Monk Excel Discussion (Misc queries) 3 February 13th 06 12:36 PM
Resetting the end of a worksheet Cachod1 New Users to Excel 1 March 29th 05 07:44 PM
Used Range is not resetting R Avery Excel Programming 8 May 28th 04 11:31 AM
Resetting variables TBA[_2_] Excel Programming 3 December 18th 03 03:44 AM


All times are GMT +1. The time now is 06:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"