Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now