'strPath 파일명을 구하고자하는 문자열
strPath = samplet
Dim blnIncludesFile As Boolean
'문자열중 / 로 파일명을 추출
lngPos = InStrRev(samplet, "/")
blnIncludesFile = InStrRev(strPath, ".") > lngPos
strPart = Right$(strPath, Len(strPath) - lngPos)
'Worksheets에 추출된 문자열을 저장
Worksheets("변환").Range("I10").Value = strPart
strPath = samplet
Dim blnIncludesFile As Boolean
'문자열중 / 로 파일명을 추출
lngPos = InStrRev(samplet, "/")
blnIncludesFile = InStrRev(strPath, ".") > lngPos
strPart = Right$(strPath, Len(strPath) - lngPos)
'Worksheets에 추출된 문자열을 저장
Worksheets("변환").Range("I10").Value = strPart
MSDN - 문자열에서 특정 부분 반환Function ParsePath(strPath As String, _ lngPart As opgParsePath) As String ' 이 프로시저는 파일 경로를 취하고 전달된 상수에 ' 따라 경로(파일 이름 제외), 드라이브 문자 또는 ' 파일 확장명을 반환합니다. Dim lngPos As Long Dim strPart As String Dim blnIncludesFile As Boolean ' 파일 경로인지 확인하십시오. ' 마지막 경로 구분 기호를 찾습니다. lngPos = InStrRev(strPath, "\") ' 마지막 백슬래시 다음의 문자열 부분에 마침표가 있는지 ' 확인합니다. blnIncludesFile = InStrRev(strPath, ".")> lngPos If lngPos > 0 Then Select Case lngPart ' 파일 이름을 반환합니다. Case opgParsePath.FILE_ONLY If blnIncludesFile Then strPart = Right$(strPath, Len(strPath) - lngPos) Else strPart = "" End If ' 경로를 반환합니다. Case opgParsePath.PATH_ONLY If blnIncludesFile Then strPart = Left$(strPath, lngPos) Else strPart = strPath End If ' 드라이브를 반환합니다. Case opgParsePath.DRIVE_ONLY strPart = Left$(strPath, 3) ' 파일 확장명을 반환합니다. Case opgParsePath.FILEEXT_ONLY If blnIncludesFile Then ' 마침표 뒤에 3 글자를 취합니다. strPart = Mid(strPath, InStrRev(strPath, ".") + 1, 3) Else strPart = "" End If Case Else strPart = "" End Select End If ParsePath = strPart ParsePath_End: Exit Function End Function
아래와 같이 직접 실행 창에서 이 함수를 호출하면 "Test.txt"가 반환됩니다.
? ParsePath("C:\Temp\Test.txt", opgParsePath.FILE_ONLY)
'잡동사니' 카테고리의 다른 글
| 신입사원 8계명 (2) | 2007/01/29 |
|---|---|
| Vista 생각했던것보다 비싸다! (6) | 2007/01/20 |
| 문자열에서 특정 부분 반환 (0) | 2007/01/18 |
| 윈도우 비스타 - Geforce 7600 / ATI 1600 이상의 그래픽카드는 필수 (4) | 2007/01/17 |
| 도토리(싸이월드) 선착순 증정! (0) | 2007/01/10 |
| 새해 첫 해돋이 풍경(포항 호미곶) (2) | 2007/01/01 |
