?
Solved

VB 6 Get File Name ( urgent )

Posted on 2003-02-28
9
Medium Priority
?
193 Views
Last Modified: 2010-05-01
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

0
Comment
Question by:Ital
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8043207
use Mid statement:

MsgBox Mid("a24.txt", 2, 1)
0
 
LVL 7

Expert Comment

by:fluglash
ID: 8043216
what do you mean by "i need to get the 2nd # of the file = " 1 ""
0
 

Author Comment

by:Ital
ID: 8043251
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)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ital
ID: 8043294
1- I need to get the FILENAME in the directory
0
 
LVL 2

Expert Comment

by:diarmaid
ID: 8043364
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.FileSystemObject")
    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

0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 140 total points
ID: 8043366
Dim fileName as String

fileName = Dir ("C:\test\test\*.txt")
0
 
LVL 2

Expert Comment

by:diarmaid
ID: 8043388
In the example folderspec is the path of the directory that you want to list the files from, ie. c:\test\test\

0
 

Expert Comment

by:RMatzka
ID: 8043404
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.
0
 

Author Comment

by:Ital
ID: 8043408
Fast, easy, excellent
thank you

Ital
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 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