Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 26
Help with Syntax 9 25
Write to file when application closes (by logoff) - VB.NET 1 15
VB.NET Repostiory Pattern 7 0
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

914 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

18 Experts available now in Live!

Get 1:1 Help Now