Question how to get any file of extension .TIF

amario26

New member
Joined
Jul 20, 2011
Messages
3
Programming Experience
1-3
Hi,

A very simple question guys...

Using the below code I want to set the '*' to any file. This folder (C:\newtemp\) will only have one TIF file in it at a time so I want it to use that file as TextBox1, but that filename is dynamic, but always with extension .TIF.

VB.NET:
TextBox1 = Convert.ToBase64String(StreamFile("C:\newtemp\" * ".TIF"))

Know how to do that?

Thanks
 
1) You will have to open an open file dialog then select it manually. Or.

2) if you want auto selection you will have to run a shell run DIR ¦ C:\newtemp\filename.text

open the file
read the file
use string functions to crop the file name.

TextBox1.text = extracted text
 
I made a program that opens up any text file in a folder, then searches it for a string. It then copies the line in the file to the rich text box.
Maybe it can help you, or you can adapt it.?

My form has
1 x button = Button1
1 x ritchtextbox = rtb1
1 x folder on the c drive = c:\files

AND any number of text files *.txt in the above folder

VB.NET:
Imports System.IO


Public Class Form1


    Public Sub FindFiles()
        Debug.WriteLine("FindFiles")
        Dim l_Dir As IO.DirectoryInfo
        Dim mypath As String = "c:\files"


        If IO.Directory.Exists(mypath) Then
            Debug.WriteLine("FindFiles.")
            l_Dir = New IO.DirectoryInfo(mypath)


            For Each l_File As IO.FileInfo In l_Dir.GetFiles
                Debug.WriteLine("FindFiles..")

                If l_File.Extension.ToLower = ".txt" Then
                    Debug.WriteLine("FindFiles...")
                    'Call SearchFile()


                    Debug.WriteLine(mypath.ToString & "\" & l_File.ToString)
                    Dim items = ReadData("London", mypath.ToString & "\" & l_File.ToString)
                    'rtb1.Text = ReadData("London", mypath.ToString & "\" & l_File.ToString)
                    Debug.WriteLine(items)
                End If
            Next
        End If


    End Sub


    Function ReadData(ByRef keyword As String, ByVal filename As String) As IEnumerable(Of String)
        Debug.WriteLine("ReadData")
        Dim result = New List(Of String)

        Using reader = New StreamReader(filename)
            Dim line As String = reader.ReadLine()
            Dim take = False
            Dim FoundStr As Integer
            Dim count As Integer = 0
            Dim fmt As String = "0##"


            Do While line IsNot Nothing
                Debug.WriteLine(":" & line)


                FoundStr = InStr(line, keyword)
                Debug.WriteLine(";" & FoundStr)
                If FoundStr > 0 Then
                    count += 1
                    rtb1.AppendText(count.ToString(fmt) & " " & line & vbCr)
                End If


                line = reader.ReadLine()
            Loop


        End Using


        Return result
    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call FindFiles()
    End Sub






End Class
 
Last edited:
Ok its not exactly what you want but the functionality is there :)

It shows you how to grab all the files in a folder, and you just have one tif. Ok ok its superseded by JohnH's comment but none the less...
 
here

Try
Dim fi As DirectoryInfo = New DirectoryInfo(path)
Dim files As FileInfo() = fi.GetFiles("*")
Dim fiNext As FileInfo
For Each fiNext In files
If Microsoft.VisualBasic.Right(fiNext.Name, 4) = ".tif" Then
'[your code here]
End If
Next
Catch
MsgBox(ErrorToString)
End Try
 
Back
Top