vbs 解析文件路径(文件名、扩展名、路径)

目录

将传入的文件路径分割为路径、文件名、扩展名三部分。

dim example
example="c:\windows\a.txt"

Function get_file_parts(in_file)
 ' Version: 0.1.0
 ' Updated: 2021-08-07
 
 dim input_path,input_filename, ext_name, left_part_name

 input_path=Left(in_file, InStrRev(in_file,"\") - 1)
 input_filename=Right(in_file,Len(in_file)-InStrRev(in_file,"\"))
 ' msgbox input_path
 ' msgbox input_filename
 left_part_name=Left(input_filename, InStrRev(input_filename,".") - 1)
 ext_name=Right(input_filename,Len(input_filename)-InStrRev(input_filename,".")+1)

 get_file_parts=input_path & "," & left_part_name & "," & ext_name

End Function

msgbox get_file_parts(example)
' c:\windows
' a
' .txt