Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining file extensions

Status
Not open for further replies.

thysonj

Programmer
Jul 6, 2001
240
US
I am trying to determine if a string contains .txt in it(like a text file: list.txt, readme.txt, etc...).
If it does I need to remove the .txt from the string but leave the file name(list, readme, etc...).
Is there a wildcard to use or what?
 
For this example, assume FileName is a string containing the name "readme.txt"

Dim ExtensionPos As Long
Dim FileName As String

FileName = "readme.txt"

'InStr will return the position of .txt in the string
ExtensionPos = InStr(FileName, ".txt")

If ExtensionPos > 0 Then
'Assign the part of the string before .txt to FileName
FileName = Mid(FileName, 1, ExtensionPos - 1)
End If


Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
'find out if it is a .txt
if right$(sYourFile,3) = "txt" then
'copy it to a new(or same) directory without the .txt
apiCopyFile sYourFile, left$(sYourFile,len(sYourfile-4), False
'delete original
KILL sYourfile
end if
Sorry it is so messy, I am on my way to lunch, I will check back
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top