vb6根據路徑獲取檔名

2021-09-22 05:21:26 字數 2471 閱讀 1815

'# txtfilepath : 控制項名'

'過程'

len(txtfilepath.text)

'取字串總長度'

strreverse txtfilepath.text '反轉字串'

instr 1

,"abcde"

,"a"

'從規定位置開始,從前往後查詢,查詢第乙個出現在的位置'

instr 1

,strreverse

(txtfilepath.text)

, "\" '反轉字串後查詢第乙個 \ 出現的位置'

msgbox "總長度:"

&len

(txtfilepath.text)

& vbcrlf & _

"翻轉查詢\位置:"

&instr(1

,strreverse

(txtfilepath.text)

, "\")

& vbcrlf & _

"反取字串::"

&mid

(txtfilepath.text,

len(txtfilepath.text),(

instr(1

,strreverse

(txtfilepath.text)

, "\")))

& vbcrlf & _

"計算開始位置:"

&len

(txtfilepath.text)-(

instr(1

,strreverse

(txtfilepath.text)

, "\")-2

)& vbcrlf & _

"計算長度:"&(

instr(1

,strreverse

(txtfilepath.text)

, "\"))-

1& vbcrlf & _

"正取字串:"

&mid

(txtfilepath.text,

len(txtfilepath.text)-(

instr(1

,strreverse

(txtfilepath.text)

,"\") - 2), (instr(1, strreverse(txtfilepath.text), "\"))-

1)'開始位置,數額越加越低,大值 - 小值'

msgbox len

(txtfilepath.text)-(

instr(1

,strreverse

(txtfilepath.text)

, "\")-2

)'長度'

msgbox

(instr(1

,strreverse

(txtfilepath.text)

, "\"))-

1'獲取路徑,擷取檔名'

msgbox mid

(txtfilepath.text,

len(txtfilepath.text)-(

instr(1

,strreverse

(txtfilepath.text)

,"\") - 2), (instr(1, strreverse(txtfilepath.text), "\"))-

1)''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

''''

'結果'

mid(

& _ txtfilepath.text,

& _ len

(txtfilepath.text)-(

instr(1

,strreverse

(txtfilepath.text)

, "\")-2

),&_

(instr(1

,strreverse

(txtfilepath.text)

, "\"))-

1& _

)'需要擷取的字串'

'字串開始的位置'

'需要擷取的長度'

獲取檔名和檔案路徑

1.問題描述 比如已經知道檔案的路徑是 c dir0 dir1 readme.txt 除了用split 的方式獲取檔名和路徑,有沒有什麼更高效的方式 2.解決辦法 os.path.dirname 路徑 os.path.basename 檔名 import os file path d work te...

獲取短檔名或路徑

一直在找.獲取短檔名或路徑的函式,可能自己笨沒有找到就自己寫了乙個.是通過呼叫winapi函式實現的.1.宣告getshortpathnamea dllimport kernel32.dll entrypoint getshortpathnamea private static extern int...

獲取檔名和路徑函式

delphi 獲取檔名路徑 2011 10 03 9 26 獲取檔名和路徑函式 extractfilename 從檔名中抽取不含路徑的檔名 extractfilepath 從檔名中抽取路徑名 extractfiledir 從檔名中抽取目錄名 extractfileext從檔名中抽取擴充套件命 例子 ...