파일경로와 파일이름

1. 프로그램이 시작된 경로를 알아내기
- App.Path 함수를 사용한다.

2. App.Path 사용시 주의할 점
- 루트 디렉토리일 경우 "\"를 함께 반환한다.
- 루트 디렉토리가 아닐 경우, 끝에 "\"가 없다.

3. 더 좋은 App.Path (출처 : http://www.freevbcode.com/ShowCode.asp?ID=878)
항상 끝에 "\"가 붙게 한다.
[code lang-vb]Public Function AppPath() As String
    Dim NewPath As String
    NewPath = App.Path
    If Right(App.Path, 1) <> "\" Then NewPath = NewPath & "\"
    AppPath = NewPath
End Function[/code]
사용예
[code lang-vb]    'Open "C:\IA Program\입력값\FormData_5장.txt" For Input As #1
    Open AppPath & "입력값\FormData_5장.txt" For Input As #1[/code]

4. 프로그램 시작 경로에서 파일명 가져오기
[code lang-vb]Function GetFileName(sFileName As String) As String
    Dim FullFilename As String
    '
    '파일이름
    If Right$(Trim$(App.Path), 1) = "\" Then
        FullFilename = App.Path + sFileName
    Else
        FullFilename = App.Path + "\" + sFileName
    End If
    '
    GetFileName = FullFilename
    '
End Function[/code]
사용예 : FormData_5장.txt를 프로그램시작경로에서 찾는다.
[code lang-vb]myFile = GetFileName("FormData_5장.txt")[/code]

5. 전체파일명에서 경로만 뽑아내기
[code lang-vb]Function GetPath(strFullFilename As String) As String
    '
    Dim strPath As String
    strPath = Mid(strFullFilename, 1, InStrRev(strFullFilename, "\", , vbTextCompare) - 1)
    If Len(strPath) = 0 Then
        strPath = App.Path
    End If
    GetPath = strPath
    '
End Function[/code]

호환성 : Visual Basic 5, 6

Posted by solarview

2008/08/28 14:48 2008/08/28 14:48
, ,
Response
No Trackback , No Comment
RSS :
http://www.solarview.net/rss/response/194

Trackback URL : http://www.solarview.net/trackback/194

« Previous : 1 : ... 119 : 120 : 121 : 122 : 123 : 124 : 125 : 126 : 127 : ... 297 : Next »