Sat80
asked on
read first line of each text file
Hi experts,
I have different txt files (unknown file numbers), I would like to load them and read only the first line of each text file and then save them to a string.
The first line of each file is only a number such as:
test1.txt
test2.txt
test3.txt
So, I wanna load them and put all the first lines to one string like this:
mystring= "1,3,4"
note:
1 is the first line of test1.txt
3 is the first line of test2.txt
4 is the first line of test3.txt
Thanks in advance
Regards
I have different txt files (unknown file numbers), I would like to load them and read only the first line of each text file and then save them to a string.
The first line of each file is only a number such as:
test1.txt
1
2
3
test2.txt
3
2
1
test3.txt
4
5
6
So, I wanna load them and put all the first lines to one string like this:
mystring= "1,3,4"
note:
1 is the first line of test1.txt
3 is the first line of test2.txt
4 is the first line of test3.txt
Thanks in advance
Regards
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@carl_tawn, thanks.
For Each filename As String In Directory.GetFiles("C:\tes t")
Can I specify the ext?
For Each filename As String In Directory.GetFiles("C:\tes t\test*.tx t") --> I got an error "Illegal characters in path"
For Each filename As String In Directory.GetFiles("C:\tes
Can I specify the ext?
For Each filename As String In Directory.GetFiles("C:\tes
I'm sorry. I posted indeed in c#
For your last question: try:
For Each filename As String In Directory.GetFiles("C:\tes t\test, "*.txt")
For your last question: try:
For Each filename As String In Directory.GetFiles("C:\tes
What Dhaest said :)
ASKER
Thank you ALL :)
It's not working because the code miss "
For Each filename As String In Directory.GetFiles("C:\tes t\test, "*.txt")
And when I added " to the code
For Each filename As String In Directory.GetFiles("C:\tes t\test", "*.txt")
It then return the same error, strange!
It's not working because the code miss "
For Each filename As String In Directory.GetFiles("C:\tes
And when I added " to the code
For Each filename As String In Directory.GetFiles("C:\tes
It then return the same error, strange!
What error?
ASKER
This one:
"Illegal characters in path"
I guess the line is wrong, coz I wanna load files not folder?
For Each filename As String In Directory.GetFiles("C:\tes t")
I want to load files starting like this:
c:\test\test*.txt
Because there are unknown files number on the test folder such as:
c:\test\test1.txt
c:\test\test2.txt
c:\test\test3.txt
"Illegal characters in path"
I guess the line is wrong, coz I wanna load files not folder?
For Each filename As String In Directory.GetFiles("C:\tes
I want to load files starting like this:
c:\test\test*.txt
Because there are unknown files number on the test folder such as:
c:\test\test1.txt
c:\test\test2.txt
c:\test\test3.txt
If you want to restrict on name as well as extension then that needs to be part of your pattern:
For Each filename As String In Directory.GetFiles("C:\test", "test*.txt")
ASKER
Yes you are right, thanks you sir :)
ASKER
I guess the code in different lang? C#?