473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Looping through directories

I am trying to loop through 2 separate directories (using the Dir) at the
same time but it seems to get confused and is mixing the files from both
directories. I tried to use the My.Computer.Get files method but I can't get
it to work other than in the myDocuments directory. It also returns the full
path when I only wnat the file name.
Jul 2 '06 #1
2 994
On Sun, 2 Jul 2006 15:12:01 -0700, Mark
<Ma**@discussions.microsoft.comwrote:
>I am trying to loop through 2 separate directories (using the Dir) at the
same time but it seems to get confused and is mixing the files from both
directories. I tried to use the My.Computer.Get files method but I can't get
it to work other than in the myDocuments directory. It also returns the full
path when I only wnat the file name.
This example gets all the files in each of two directories and
populates two list boxes with the respective filenames:

Imports System.IO

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dir1 As New DirectoryInfo("C:\Windows")
Dim FoundFiles1 As FileInfo() = dir1.GetFiles()
Dim fiTemp As FileInfo
For Each fiTemp In FoundFiles1
Me.ListBox1.Items.Add(fiTemp)
Next fiTemp

Dim dir2 As New DirectoryInfo("C:\Windows\System32")
Dim FoundFiles2 As FileInfo() = dir2.GetFiles()
For Each fiTemp In FoundFiles2
Me.ListBox2.Items.Add(fiTemp)
Next fiTemp
End Sub

Gene
Jul 3 '06 #2
Mark wrote:
I am trying to loop through 2 separate directories (using the Dir) at the
same time but it seems to get confused and is mixing the files from both
directories.
Dir uses an internal "pointer" to keep track of where it is within the
current directory. You /can't/ "scan" two directories (or
sub-directories) at the same time.

Read up on the Directory class, particularly the GetFiles method(s).

For Each sFile As String _
In Directory.GetFiles( "path", "*.*" )
Debug.WriteLine( sFile )
Next

HTH,
Phill W.
Jul 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JP SIngh | last post by:
Hi All Please can someone help me solve this issue. I have a database table the structure of which are given below. Profile Table EmployeeNumber FirstName
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
1
by: Heath | last post by:
I'm dealing with a C# application that monitors changes to the file system, and need to exclude irrelevent directories, temp directories for example. Is there any way to identify such...
2
by: Jeffry van de Vuurst | last post by:
Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of you has some ideas about this. I'm using the...
5
by: talktozee | last post by:
Hello, everyone! Here's are the basics: 1. The query looks at all positions that are active and haven't been filled. 2. It then has to look at every single position and determine three...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: rn5a | last post by:
A ListBox lists all the folders & files existing in a directory named 'MyDir' on the server. Assume that the ListBox lists 2 directories - 'Dir1' & 'Dir2' i.e. these 2 directories reside in the...
6
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
4
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.