Global It Leader!!



 
 

VB FileSystemObject를 이용한 파일 읽기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 4,933회 작성일 13-12-20 21:05

본문

FileSystemObject는 Scrrun.dll에서 찾을 수 있습니다. Scrrun.dll에는 FileSystemOject 외에도 파일 입/출력 및 기타 작업에 사용할 수 있는 File 개체, TextStreamObject 개체, Folder 개체 및 Drive 개체가 있습니다. 이러한 개체 모두에는 도움말 파일에서 자세히 설명하는 속성과 메서드가 포함되어 있습니다.

Scrrun.dll은 다음 패키지 중 하나를 설치하여 구할 수 있습니다.
Windows 스크립트 호스트
Windows NT 옵션 팩
Microsoft Internet Information Server 3.0
Scripting 3.1 업그레이드
Visual Studio 6.0
Visual Basic 6.0

FileSystemObject는 원래 Visual Basic Scripting Edition용으로 만들어졌습니다. 따라서 FileSystemObject는 Visual Basic 또는 Visual Basic for Applications용 개체 라이브러리에 포함되어 있지 않습니다. FileSystemObject를 사용하려면 프로젝트의 프로젝트 참조 대화 상자에서 Microsoft Scripting 런타임을 선택해야 합니다.

다음 예제에서는 일부 FileSystemObject 기능을 구현하는 방법을 보여 줍니다. 자세한 내용은 Visual Basic 도움말 파일과 Visual Basic 온라인 설명서를 참조하십시오.

예제 프로젝트를 만드는 단계

  1. Visual Basic에서 새로운 표준 EXE 프로젝트를 시작합니다. 기본적으로 Form1이 만들어집니다.
  2. 프로젝트 메뉴에서 참조를 누르고 Microsoft Scripting 런타임을 선택합니다. 목록에 Microsoft Scripting 런타임이 없으면 시스템에서 Scrrun.dll을 찾습니다. 필요한 경우 위에 나열된 도구 중 하나를 설치합니다.
  3. Form1에 네 개의 CommandButton 컨트롤을 추가합니다. CommandButton 컨트롤은 다음과 같은 기능을 보여 줍니다.
    표 축소표 확대
    Command1: FileSystemObject 및 TextStreamObject를 사용하여
    기존 텍스트 파일을 읽는 방법
    Command2: FileSystemObject 및 File 개체를 사용하여
    파일 정보를 보는 방법
    Command3: FileSystemObject 및 Folder 개체를 사용하여
    폴더 사이의 이동을 반복하는 방법
    Command4: FileSystemObject 및 Drive 개체를 사용하여
    드라이브 정보를 보는 방법
  4. Form1의 일반 선언 구역에 다음 코드를 붙여 넣습니다.
          Option Explicit
    
          Private Sub Command1_Click()
            'Declare variables.
            Dim fso As New FileSystemObject
            Dim ts As TextStream
            'Open file.
            Set ts = fso.OpenTextFile(Environ("windir") & "\system.ini")
            'Loop while not at the end of the file.
            Do While Not ts.AtEndOfStream
              Debug.Print ts.ReadLine
            Loop
            'Close the file.
            ts.Close
          End Sub
    
          Private Sub Command2_Click()
             Dim fso As New FileSystemObject
             Dim f As File
             'Get a reference to the File object.
             Set f = fso.GetFile(Environ("windir") & "\system.ini")
             MsgBox f.Size 'displays size of file
          End Sub
    
          Private Sub Command3_Click()
             Dim fso As New FileSystemObject
             Dim f As Folder, sf As Folder, path As String
             'Initialize path.
             path = Environ("windir")
             'Get a reference to the Folder object.
             Set f = fso.GetFolder(path)
             'Iterate through subfolders.
             For Each sf In f.SubFolders
               Debug.Print sf.Name
             Next
          End Sub
    
          Private Sub Command4_Click()
             Dim fso As New FileSystemObject
             Dim mydrive As Drive
             Dim path As String
             'Initialize path.
             path = "C:\"
             'Get object.
             Set mydrive = fso.GetDrive(path)
             'Check for success.
             MsgBox mydrive.DriveLetter 'displays "C"
          End Sub
    
    					
  5. 프로젝트를 실행합니다. 각 CommandButton 컨트롤을 누르고 결과를 관찰합니다.

댓글목록

등록된 댓글이 없습니다.

전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
75 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4524 02-17
74 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7038 02-17
73 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4584 02-11
72 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4446 02-11
71 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4336 02-07
70 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4321 08-04
69 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4477 12-25
68 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11588 12-25
67 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5439 12-24
66 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4870 12-24
65 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5104 12-20
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4934 12-20
63 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6298 12-20
62 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4895 12-20
61 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10185 12-19
60 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4744 12-17
59 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6779 12-17
58 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4642 12-16
57 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4400 12-16
56 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4526 12-16