|
-
Jun 11th, 2000, 08:16 PM
#1
Thread Starter
Hyperactive Member
Dir Question
Lets say I had code that looked for a any file called cat in c:\...using the format \cat.* Once my program has found that, how can I get it to tell me what extension it is in a msg box.....
Should look something like this
if Dir$(\cat & ".*") <> "" then
msgbox ????????????????
end if
Help me out with second line...trying to find what .* of cat is...thanks for the help!!
-RaY
VB .Net 2010 (Ultimate)
-
Jun 11th, 2000, 08:54 PM
#2
PowerPoster
Dir()
This will do what you want.
Code:
if Dir$(\cat & ".*") <> "" then
While Dir() <> ""
MsgBox Dir()
Wend
end if
-
Jun 11th, 2000, 09:06 PM
#3
Thread Starter
Hyperactive Member
That works great, however
First off thanks a lot for responding, but maybe you can help me a little further....
1. The code fails to work if the Dir is not \....ex
Sub Command1_Click ()
If Dir$("\Flag\Serial\SerWS\1" & ".*") <> "" Then
While Dir <> ""
MsgBox Dir
Wend
End If
End Sub
Above doesn't notice the file and it does exist... 1.1 is in that directory..
2. It tells me the whole file, is there anyway just to tell me the extension....ex instead of saying cat.bat...can it just say "bat"...... Thanks!!
-RaY
VB .Net 2010 (Ultimate)
-
Jun 11th, 2000, 09:26 PM
#4
Thread Starter
Hyperactive Member
I figured out some
I figured out the answer to my first question
Dim sFilename As String
Dim sPath As String
sPath = "\flag\serial\serws\1" & ".*"
sFilename = Dir$(sPath)
Do While sFilename > ""
text1.Text = sFilename
sFilename = Dir$
Loop
But how do i get it to tell me just just the extension not the whole file
-RaY
VB .Net 2010 (Ultimate)
-
Jun 13th, 2000, 05:53 AM
#5
New Member
If you are sure that the extension will be exactly 3 characters long, then you can get away with:
sExtension = right(sFilename, 3)
If the number of characters in the extension is likely to be something other than 3, then there is a simple work around:
sExtension = right(sFilename, len(sFilename) - _
instr(sFilename, ".")
This assumes there is only one "." in the file name. As Instr() will only find the first occurance of string2 in string1 then if more than one '.' is present then more than the extension will be returned. To deal with more, you keep putting the result of the above into a 'while'/'do until' loop until there are no '.'s left in sExtension. You may want to check the intstr command and which string is searched for in which, it's late and I can't be bothered to load VB.
Hope it helps!
Matt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|