473,624 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles BtnConfirmNext. Click

Dim fi As New FileInfo("c:\te st.tif")
Dim di As DirectoryInfo = fi.Directory
Dim NextImage As IEnumerator
NextImage = di.GetFiles.Get Enumerator
NextImage.MoveN ext()
Dim fi2 As FileInfo = NextImage.Curre nt

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

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

Thanks!
John

Nov 21 '05 #1
4 3274
"johnb41" <or****@informa tik.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(B yVal sender As System.Object, ByVal e
As
System.EventArg s) Handles BtnConfirmNext. Click

Dim fi As New FileInfo("c:\te st.tif")
Dim di As DirectoryInfo = fi.Directory
Dim NextImage As IEnumerator
NextImage = di.GetFiles.Get Enumerator
NextImage.MoveN ext()
Dim fi2 As FileInfo = NextImage.Curre nt

MessageBox.Show (fi2.Name)
'I was hoping fi2.name would yield the "NEXT" filename
'in the folder. Instead it gives me "c:\test.ti f"
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.f ilenames, retrieved the
file names, and put them in an arraylist object.
- Then I did arraylist.index of(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.f ilenames, retrieved the
file names, and put them in an arraylist object.
- Then I did arraylist.index of(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(Syste m.IO.Directory. GetFiles("C:\") )
n = files.BinarySea rch("C:\test.ti f")
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
3714
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 results: $query = "select id, name, addr1, addr2, city from mytable where id=" ..$id; $connection = mysql_connect(etc etc) ....
1
1985
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
1866
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 out userid, password, and click on "login", what exactly is sent to Yahoo? 2. When I click on "next" to fetch the next mail, what exactly is sent to Yahoo?
3
2218
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 values. I need it to advance the form to the next group of duplicate values not just the next record.
2
2452
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
1812
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 controls with a tag property of "1", If they are null, I want to stop the loop and setfocus on the control. The below code works Except it will not stop looping when a control is null. It will display the msgBox and then continue to the next...
11
47982
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
3818
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 Colors Red = 5 Green = 7 Blue = 16 Yellow = 2
10
4789
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 if value of the current field is not the same value of the next row. eg:
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.