Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How to open text file with half of its name


How to open text file with half of its name

Author
Message
otomatis
otomatis
Forum God
Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)Forum God (309 reputation)

Group: Forum Members
Posts: 1, Visits: 1
Hi, all

Does somebody know how to open text file with half of its name using vb6. example i have 2 files in  C:\,
they are :
1. Myfile10001.txt
2. Myfile20001.txt
I want to read file no.2 with 7 characters first (Myfile2xxxx.txt), and ignore next characters.

my script is :
Option Explicit
dim file1, file2, astrx
astrx = "*"
file1 ="c:\Myfile10001.txt"
file2 ="c:\Myfile2" & astrx & ".txt"

'this is run
Sub OpenTextFile1
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs1, f1
    Set fs1 = CreateObject("Scripting.FileSystemObject")
    Set f1 = fs1.OpenTextFile(file1, ForReading,TristateFalse)
    f1.Close
End Sub

'this is error
Sub OpenTextFile2
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs2, f2
    Set fs2 = CreateObject("Scripting.FileSystemObject")
    Set f2 = fs2.OpenTextFile(file2, ForReading,TristateFalse)
    f2.Close
End Sub

Mark
Mark
Forum God
Forum God (142K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
The Dir function is probably what you are looking for. Here is a quick sample.

Private Sub Command1_Click()
Const astrx As String = "*"
Dim strPath As String
Dim strFilePath As String
Dim strFileName As String

    ' I have on my c drive AUTOEXEC.BAT
    ' So this is what is being tested for
    
    strPath = "c:\"
    strFileName = Dir(strPath & "AUTO" & astrx & ".BAT")
    strFilePath = strPath & strFileName
    
    MsgBox strFilePath

End Sub

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search