?
Solved

VB 6 Get File Name ( urgent )

Posted on 2003-02-28
9
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 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