Solved

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

Posted on 2016-11-08
1
33 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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