?
Solved

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

Posted on 2016-11-08
1
Medium Priority
?
49 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 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