Ital
asked on
VB 6 Get File Name ( urgent )
hi
i want to get the name of the file of a certain diretory ( ex.: c:\test\test )
then
if the file name is
a10.txt
i need to get the 2nd # of the file = " 1 "
if its
a24 = " 2 "
thx
Ital
i want to get the name of the file of a certain diretory ( ex.: c:\test\test )
then
if the file name is
a10.txt
i need to get the 2nd # of the file = " 1 "
if its
a24 = " 2 "
thx
Ital
what do you mean by "i need to get the 2nd # of the file = " 1 ""
ASKER
i got a folder =
c:\test\test\
i need to get the first file inside that folder
1- how can we do that
then when i have it
if the file name is a13.txt
i need the 2 "character " of the #
Mid("a13.txt", 2, 1) // it looks good
but i need #1 first
and can i do : mid(FILENAME,2,1)
c:\test\test\
i need to get the first file inside that folder
1- how can we do that
then when i have it
if the file name is a13.txt
i need the 2 "character " of the #
Mid("a13.txt", 2, 1) // it looks good
but i need #1 first
and can i do : mid(FILENAME,2,1)
ASKER
1- I need to get the FILENAME in the directory
You should be able to do it using the Files collection of the FileSystemObject. The FileSystemObject is part of the Microsoft scripting runtime library so you will need to add a reference to that library first.
Here is some example code from MSDN
Sub ShowFolderList(folderspec)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.Fi leSystemOb ject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & vbCrLf
Next
MsgBox s
End Sub
Here is some example code from MSDN
Sub ShowFolderList(folderspec)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.Fi
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & vbCrLf
Next
MsgBox s
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In the example folderspec is the path of the directory that you want to list the files from, ie. c:\test\test\
Your first problem can be solved using the Dir statement:
msgbox Dir("c:\test\test\*.*")
But caution, it is a bit unclear what is meant by the "first" file in a directory, because that depends on the sort order.
For the second problem use the Mid statement, as shown by others. The syntax is Mid(Filename, StartPosition, Length), so Mid("a13.txt",1,1) gives you the first character, and Mid("a13.txt",2,1) gives you the second.
msgbox Dir("c:\test\test\*.*")
But caution, it is a bit unclear what is meant by the "first" file in a directory, because that depends on the sort order.
For the second problem use the Mid statement, as shown by others. The syntax is Mid(Filename, StartPosition, Length), so Mid("a13.txt",1,1) gives you the first character, and Mid("a13.txt",2,1) gives you the second.
ASKER
Fast, easy, excellent
thank you
Ital
thank you
Ital
MsgBox Mid("a24.txt", 2, 1)