Solved

how to open a file with any name (*) and specific extension in VB

Posted on 2016-11-08
1
38 Views
Last Modified: 2016-11-08
I am trying to make a timer1 in VB open an do a streamread on any file that has a specific extension (example .txt), i have not been able to make it
i tried

 Dim inputfile As String = "C:\1PROJECTS\INPUT\*.TXT"

Private Sub fileexisttimer_Tick(sender As Object, e As EventArgs) Handles fileexisttimer.Tick
        If File.Exists(inputfile) Then
                   Dim i As Integer = 1
        
            Dim sr1 As New StreamReader(inputfile)
 
.........
end sub

Open in new window


 but when the SR (streamreader starts, it will not recognize or open the file) ...
is there a way to do this?

thanks
0
Comment
Question by:Henry Ottiz
1 Comment
 

Accepted Solution

by:
Henry Ottiz earned 0 total points
ID: 41879500
I went with a different approach

if i find a file with the specific extension buit any name  inside the folder, i rename the file to the specific name for the Streamreader to accept it...
i created a new timer for that routine and the streamreader timer stop and starts that timer so they do not clash..

  Private Sub renameFilesInFolder()
        Dim sourcePath As String = inputfolder
        Dim searchPattern As String = "*.txt"
     
        For Each fileName As String In Directory.GetFiles(sourcePath, searchPattern, SearchOption.AllDirectories)
            File.Move(Path.Combine(sourcePath, fileName), Path.Combine(sourcePath, "myfiletosue" & ".txt"))
         
        Next
    End Sub

    Private Sub Timerrenamefile_Tick(sender As Object, e As EventArgs) Handles Timerrenamefile.Tick
        renameFilesInFolder()
    End Sub

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question