gpt4 book ai didi

vb6 - 如何只获取文件?

转载 作者:行者123 更新时间:2023-12-04 14:08:37 26 4
gpt4 key购买 nike

如何仅从文件的完整路径获取文件名?

MY path -  C:\Documents and Settings\Arshad\My Documents\ravi.txt

最佳答案

看看这个: Retrieve Filename without Path or Extension .

这是上面链接中的函数:

Public Function GetFileName(flname As String) As String

'Get the filename without the path or extension.
'Input Values:
' flname - path and filename of file.
'Return Value:
' GetFileName - name of file without the extension.

Dim posn As Integer, i As Integer
Dim fName As String

posn = 0
'find the position of the last "\" character in filename
For i = 1 To Len(flname)
If (Mid(flname, i, 1) = "\") Then posn = i
Next i

'get filename without path
fName = Right(flname, Len(flname) - posn)

'get filename without extension
posn = InStr(fName, ".")
If posn <> 0 Then
fName = Left(fName, posn - 1)
End If
GetFileName = fName
End Function

输入时

C:\Documents and Settings\Arshad\My Documents\ravi.txt



这个函数返回

ravi



该函数是这样调用的:
Dim FileName As String
FileName = GetFileName("C:\Documents and Settings\Arshad\My Documents\ravi.txt")

关于vb6 - 如何只获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1403980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com