473,378 Members | 1,354 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,378 software developers and data experts.

Retrieving "Next" file in a folder

In my application, the user opens up a Tiff image. (The file does NOT
necessarily have to be the first file in the folder; it could by
anywhere.) When i'm done viewing (doing whatever) with the image I
need to open up the "Next" Tiff file in the folder. This should be
done by clicking a button instead of using the FileOpen dialog again
and again.

Here is my approach, which isn't working:

Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnConfirmNext.Click

Dim fi As New FileInfo("c:\test.tif")
Dim di As DirectoryInfo = fi.Directory
Dim NextImage As IEnumerator
NextImage = di.GetFiles.GetEnumerator
NextImage.MoveNext()
Dim fi2 As FileInfo = NextImage.Current

MessageBox.Show(fi2.Name)
'I was hoping fi2.name would yield the "NEXT" filename
'in the folder. Instead it gives me "c:\test.tif"
End Sub

My approach for this is probably way off. Can anyone help?

Thanks!
John

Nov 21 '05 #1
4 3260
"johnb41" <or****@informatik.com> schrieb
In my application, the user opens up a Tiff image. (The file does
NOT necessarily have to be the first file in the folder; it could
by anywhere.) When i'm done viewing (doing whatever) with the image
I need to open up the "Next" Tiff file in the folder. This should
be done by clicking a button instead of using the FileOpen dialog
again and again.

Here is my approach, which isn't working:

Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles BtnConfirmNext.Click

Dim fi As New FileInfo("c:\test.tif")
Dim di As DirectoryInfo = fi.Directory
Dim NextImage As IEnumerator
NextImage = di.GetFiles.GetEnumerator
NextImage.MoveNext()
Dim fi2 As FileInfo = NextImage.Current

MessageBox.Show(fi2.Name)
'I was hoping fi2.name would yield the "NEXT" filename
'in the folder. Instead it gives me "c:\test.tif"
End Sub

My approach for this is probably way off. Can anyone help?

The enumerator starts with the first file in the directory. Files in a
directory don't have a specific order, but you could first enumerate all the
files in the directory til test.tif is reached, then MoveNext to the next
file.

Armin

Nov 21 '05 #2
John,

The Dir function allows you to browse through the files in a
Folder/Directory. Here is some code that I wrote up. I haven't tested it so I
won't be surprised if it doesn't run the 1st time. However you should get the
idea from the code

///
Private Sub IterateFolder()
Dim File As String
Dim Path as String

Path = "c:\"
File = Dir$(Path & "*.tiff")

While File <> ""
MsgBox(File)
File = Dir()
End While

End Sub
\\\

HTH
Nov 21 '05 #3
Thanks Armin and Sarika,

Armin:
I tried what you suggested, but just couldn't find a way to get the
"next" file.

Sarika:
Interesting idea, thanks. Before I read your suggestion, I found my
own solution:

- First I iterated through the directoryinfo.filenames, retrieved the
file names, and put them in an arraylist object.
- Then I did arraylist.indexof(currentfile) to find out the index
position of the current file.
- Add 1 to it, and then that's your next file.
- Probably too much code for this, but it works.

Thanks again!
John

Nov 21 '05 #4
On 19 May 2005 09:38:58 -0700, johnb41 wrote:
Thanks Armin and Sarika,

Armin:
I tried what you suggested, but just couldn't find a way to get the
"next" file.

Sarika:
Interesting idea, thanks. Before I read your suggestion, I found my
own solution:

- First I iterated through the directoryinfo.filenames, retrieved the
file names, and put them in an arraylist object.
- Then I did arraylist.indexof(currentfile) to find out the index
position of the current file.
- Add 1 to it, and then that's your next file.
- Probably too much code for this, but it works.

Thanks again!
John


Another approach: same idea, somewhat less code:

Dim files as ArrayList
dim n as Integer
Dim nextfile as String
files = new ArrayList(System.IO.Directory.GetFiles("C:\"))
n = files.BinarySearch("C:\test.tif")
If n < 0 then
' C:\test.tif wasn't found - return first filename
nextfile = files(0)
Elseif n >= files.Count Then
' C:\test.tif is last file - return empty string
nextfile = ""
Else
' return next file
nextfile = files(n+1)
End If
Nov 21 '05 #5

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

Similar topics

8
by: joe | last post by:
Can anyone help me out by either telling me how to get to the result i need or by pointing me to some documentation about the following question: A certain query to a database give me eg 100...
1
by: tnhoe | last post by:
Hi, <Form method='post' action="next.htm?btn="+"this.myform.myobj.value"> What is the correct syntax for above ? Regards Hoe
2
by: John Smith | last post by:
I have more than 4,000 pieces of email in my Yahoo account. I would like to write a program to download them all. In order to write such a program, I need to know a few things. 1. After I fill...
3
by: domcatanzarite | last post by:
How would one create a button that on click advances the form to the next "non recurring record" as opposed to the next record. The field the button needs to que from has groups of duplicate...
2
by: ntsNews | last post by:
Hi, Using the built in command "Find Next" is there a way to have the Match Drop Down Menu to default to "Start of Field"... or can it be the only option? GCM
3
by: Dale | last post by:
Access 2000 I am trying to check the form to be sure that required fields are entered. For each required field (Control) I have set the tag property to "1". I am trying to loop through all...
11
by: Maxwell2006 | last post by:
Hi, I know that this is not a good practice, but I wonder do we have "on error resume next" in C#? Thanks,
2
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
how do I code generic functions to return the next item in an enumeration a) sorted by name, b) sorted by value c) sorted by declaration in a round-robin style ? for example the enum is Enum...
10
by: craig.keightley | last post by:
I am trying to get the next row within a loop for a script i am developing... I need to display a final table row within the table that i have displayed on the page, but i only want to show it...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.