ASP3.0 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : 19. FSO(File System Object) : 파일(File) 처리
글번호: 27
작성자: 관리자
작성일: 2001/03/03 오전 1:11:00
조회수: 9751
■ 11일차 강의 - FSO(File System Object)


● FileSystemObject 객체는 컴퓨터의 파일 시스템에 액세스하기 위한 메소드를 제공한다.


● FileSystemObject 객체의 각 메소드를 사용하면, 파일과 폴더를 생성 또는 삭제 및 정보를 변경할 수 있다.


● FileSystemObject 객체의 인스턴스(사례) 생성

Set 인스턴스명 = Server.CreateObject("Scripting.FileSystemObject")

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

이렇게 정의하면,

objFSO란 이름으로 FileSystemObjec의 모든 메소드를 사용할 수 있게된다.


● C드라이브의 정보

<% '드라이브 정보얻어오기
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>

<%
Set Cdrive = objFSO.GetDrive("C:")
%>

남은용량 : <%= Cdrive.FreeSpace %><br>
전체용량 : <%= Cdrive.TotalSize %><br>


● 파일의 정보 얻어오기

<% '파일의 정보얻어오기.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>

<%
Set FileInfo = objFSO.GetFile("C:\config.sys")
%>

파일크기 : <%= FileInfo.size %><br>
파일타입 : <%= FileInfo.type %><br>
파일경로 : <%= FileInfo.path %><br>


● 파일의 생성

<% '파일의 생성.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>

<%
Set objFile = objFSO.CreateTextFile("C:\test.txt",true,false) '첫번째 인자는 경로, 2.덮어쓰기 여부, 3. 유니코드로 생성(T) 또는 아스티로 생성(F) 여부
%>

<%
if objFSO.FileExists("C:\test.txt") then
   Response.Write "파일이 만들어졌습니다."
else
   Response.Write "파일이 만들어지지 못했습니다."
end if
%>

  
● 파일에 글쓰기

<% '파일에 글쓰기.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>

<%
Set objFile = objFSO.OpenTextFile("C:\test.txt",8) '1은 읽기전용, 8은 읽고쓰기 모드%>

<%
objFile.WriteLine("test파일을 읽고쓰기모드로 엽고 글을 씁니다.")
objFile.WriteLine("test파일의 두번째 라인에 글을 씁니다.")
objFile.WriteLine("test파일의 세번째 라인에 글을 씁니다.")
objFile.close 'close메소드로 열었던 파일을 닫아줌.
%>


● 파일에서 글읽어오기

<% '파일에서 글읽어오기.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>

<%
Set objFile = objFSO.OpenTextFile("C:\test.txt",1) '1은 읽기전용, 8은 읽고쓰기 모드%>

<%
Do While objFile.AtEndOfStream <> True
   Response.Write objFile.ReadLine & "<br>"
loop

'content = objFile.readall
'str = replace(content,chr(13)&chr(10),"<br>")
'Response.Write str
%>


---------------------------------------------------------
'파일 크기를 계산해서 알맞은 단위로 변환해줌. (바이트 수)
Function ConvertToFileSize(intByte)

     intFileSize = Int(intByte)
    
     If intFileSize >= 1048576 Then
          ConvertToFileSize = FormatNumber((intByte / 1048576), 2) & " MB"
     Else
          If intFileSize >= 1024 Then
               ConvertToFileSize = FormatNumber((intByte / 1024), 0) & " KB"
          Else
               ConvertToFileSize = intByte & " Byte(s)"
          End If
     End If

End Function
---------------------------------------------------------
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트

(댓글을 남기려면 로그인이 필요합니다.)

관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 20. 기본형 게시판 작성 프로젝트 - 관리자 2001-07-08 7446
현재글 19. FSO(File System Object) : 파일(File) 처리 - 관리자 2001-03-03 9751
  FSO(File System Object) Bible: 파일(File) 처리 관련 예... FSO_BIBLE.zip(21 KB) 레드플러스 2004-04-22 5217
  FSO_GetDrive.asp : C드라이브 정보 얻기 19_1.gif(14 KB) 레드플러스 2004-04-27 5189
  FSO_GetDriveUp.asp : C드라이브 정보 얻기(기능 추가) 19_2.gif(14 KB) 레드플러스 2004-04-27 5539
  FSO_GetFolder.asp : C:\Temp 폴더의 크기 얻기 19_3.gif(13 KB) 레드플러스 2004-04-27 6072
  웹사이트 용량 구하기 예제 - 레드플러스 2004-10-14 5883
  FSO_CreateTextFile.asp : 텍스트 파일 생성하기 19_4.gif(28 KB) 레드플러스 2004-04-27 7953
  FSO_WriteLine.asp : 텍스트 파일에 글 쓰기 19_5.gif(17 KB) 레드플러스 2004-04-27 6410
  FSO_ReadLine.asp : 텍스트 파일로부터 데이터 읽기 19_6.gif(15 KB) 레드플러스 2004-04-27 8381
다음글 18. CDO(Collaboration Data Object) : 메일 전송(SMTP... - 관리자 2000-12-27 6963
 
손님 사용자 Anonymous (손님)
로그인 Home