'FSO'에 해당되는 글 2건

  1. 2013.10.24 폴더검색 fso
  2. 2013.10.24 FSO 객체(FileSystemObject)

폴더검색 fso

ASP 2013. 10. 24. 12:27

'파일/폴더 관련 변수
Dim fso, folders, SubFolders, folderPath, files, file

'파일객체 인스턴스 생성
Set fso = Server.CreateObject("Scripting.FileSystemObject")

'경로 설정(Server.MapPath:해당폴더의 물리적 경로 반환)
folderPath = Server.MapPath(CK_FD_SM2)

 

'해당 폴더가 있다면
If fso.FolderExists(folderPath) Then
      '해당 폴더 객체를 가져온다.
      Set folders = fso.GetFolder(folderPath)
 
      '해당 폴더 내 다른 폴더가 있는지 검사
      Set SubFolders = folders.SubFolders    

      '해당 폴더 내 다른 폴더가 있다면..
      If SubFolders.Count <> 0 Then
            Response.Write "해당 폴더내에 있는 폴더 수: "& folders.Count &"<br>"
           '해당 폴더 내 다른 폴더가 없다면..
      Else
            Response.Write "해당 폴더내에 다른 폴더가 없습니다.<br>"
      End If

 

      '해당 폴더 내 파일 목록 받아오기
      Set files = folders.Files
      '해당 폴더 내 파일이 있다면...
      If files.Count <>0 then
            Response.Write "<br>해당 폴더 내에 있는 파일 수: "& files.Count & "<br>"
 
            i=1
            '해당 폴더 내 파일 목록 출력
            For Each file In files  
                  Response.Write i&". "&file.name&" ("&file.type&")<br>"
                  i=i+1
            Next

      '해당 폴더 내 파일이 없다면..
      Else
            Response.Write "해당 폴더 내 파일이 없습니다.<br>"
      End If  

 
     Set files = Nothing
    

     Set SubFolders = Nothing
     Set folders = nothing
'해당 폴더가 없다면
Else
      Response.Write "해당 폴더가 없습니다.<br>"
End If

Set fso = nothing

'ASP' 카테고리의 다른 글

엑셀전환시 <br>태그  (0) 2013.10.28
ABCUpload 이용해서 파일 업로드 및 다운로드  (0) 2013.10.26
asp 모든폼 갖고오기  (0) 2013.10.24
Dext sumnail 새창으로 메일 보기  (0) 2013.10.24
FSO 객체(FileSystemObject)  (0) 2013.10.24
Posted by 초보용
,

FSO 객체(FileSystemObject)

ASP 2013. 10. 24. 12:20

서버에 허용된 하드디스크의 드라이브, 폴더, 파일에 대해 관리하는 스크립팅 객체

 

FSO 안에서도 Drive, Folder, File 객체가 있다.

 

Drive 객체

 

Drive 객체의 메서드, 속성

 

메서드

설명

GetDrive(drive명)

선택된 드라이브 객체반환

 

속성

설명

DriveLetter

드라이브 문자 반환

FileSystem

드라이브 파일시스템 형식 반환

TotalSize

드라이브 전체용량 반환

AvailableSpace

드라이브에서 사용가능한 용량 반환

 

 

자기 자신의 하드디스크 정보에 관련된 예제입니다..

 

<%

Dim objFSO, objCdrv

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

Set objCdrv = objFSO.GetDrive("C:")

%>

<h2><font color="4b0082">FSO객체의 DRIVE객체를 이용한 HDD정보확인</font><hr size="3" noshade color="a52a2a"></h2>

<body>

<center>

<table border="1" width="400" cellpadding="5">

<tr><td align="center">구분</td><td align="center">내용</td></tr>

<tr>

<td width="200">드라이브명</td>

<td><%=objCdrv.DriveLetter%></td>

</tr>

<tr>

<td>파일시스템형식</td>

<td><%=objCdrv.FileSystem%></td>

</tr>

<tr>

<td>전체 디스크 공간</td>

<td><%=Round(objCdrv.TotalSize/1024^3, 1)%> GBytes</td>

</tr>

<tr>

<td>사용가능한 디스크 공간</td>

<td><%=Round(objCdrv.AvailableSpace/1024^3, 1)%> GBytes</td>

</tr>

</table>

</center>

</body>

 

 

 

Folder 객체

 

Folder 객체의 메서드, 속성

 

메서드

설명

GetFolder(경로포함 folder명)

선택된 폴더 객체반환

속성

설명

Name

폴더명 반환

DateCreated

폴더가 만들어진 날짜/시간 반환

Path

폴더의 경로반환

Size

폴더의 크기반환

SubFolders

폴더에 포함된 모든 폴더반환

Files

폴더에 포함된 모든 파일반환

 

 

C:\inetpub\wwwroot 정보에 관련된 예제(이 폴더가 있어야 함)

 

<%Option explicit%>

<%

Dim objFSO, objDir, objSubdir

 

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

Set objDir = objFSO.GetFolder("C:\inetpub\wwwroot")

%>

<h2>

<font color="4b0082">FSO객체의 Folder객체를 이용한 디렉터리정보확인</font>

<hr size="3" noshade color="a52a2a"></h2>

 

<body>

<center>

<table border="0" cellpadding="5">

<tr><td>폴더명 : <%=objDir.Name%></td></tr>

<tr><td>생성일 : <%=objDir.DateCreated%></td></tr>

<tr><td>폴더경로 : <%=objDir.Path%></td></tr>

<tr><td>폴더크기 : <%=objDir.Size%> Bytes</td></tr>

<tr><td>&nbsp;</td></tr>

</table>

 

<table border="0" width="400" cellpadding="5">

<tr><td align="center">하위폴더목록</td><td align="center">폴더의 파일목록</td></tr>

<tr><td align="center" colspan="2"><b>------------------------------------------</b></td></tr>

<tr>

<td valign="top">

<table>

<%

For Each objSubdir In objDir.SubFolders

Response.write "<tr><td style='padding-left:30px'>"

Response.write objSubdir.Name

Response.write "</td></tr>"

Next

%>

</table>

</td>

<td>

<table>

<%

For Each objSubdir In objDir.Files

Response.write "<tr><td style='padding-left:30px'>"

Response.write objSubdir.Name

Response.write "</td></tr>"

Next

%>

</table>

</td>

</tr>

</table>

</center>

</body>

 

 

File 객체

 

File 객체의 메서드, 속성

 

메서드

설명

GetFile(경로포함 file명)

파일 객체반환

FileExists(경로포함 file명)

파일 존재 여부를 True, False로 반환

DeleteFile(경로포함 file명)

파일 삭제

CreateTextFile(경로포함 file명, over)

텍스트파일 생성, over - true : 겹쳐쓰기가능, false : 읽기전용

OpenTextFile(경로포함 file명, io)

텍스트파일 열기, io - 1 : 읽기, 2 : 쓰기, 8 : 덧붙이기

 

cf. 파일을 생성하거나 수정, 삭제할 경우에는 IIS의 웹디렉터리에서 쓰기 권한을 설정해야 하며, 해당 폴더에서 수정 및 쓰기 권한을 설정해 주어야 한다.

 

속성

설명

Name

파일명 반환

Size

파일의 크기반환

Type

파일의 형식반환

DateCreated

파일이 만들어진 날짜/시간 반환

DateLastModified

파일이 마지막으로 수정된 날짜/시간 반환

 

C:\inetpub\wwwroot\iisstart.htm 파일 정보에 관련된 예제

 

<%

Dim objFSO, objFile

 

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

Set objFile = objFSO.GetFile("C:\inetpub\wwwroot\iisstart.htm")

%>

<h2><font color="4b0082">FSO객체의 File객체를 이용한 디렉터리정보확인</font>

<hr size="3" noshade color="a52a2a"></h2>

 

<body>

<center>

<table border="1" width="800" cellpadding="5">

<tr>

<td align="center">파일명</td>

<td align="center">파일크기</td>

<td align="center">파일종류</td>

<td align="center">만든날짜</td>

<td align="center">수정한날짜</td>

</tr>

<tr>

<td align="center"><%=objFile.Name%></td>

<td align="center"><%=objFile.Size%> Byte</td>

<td align="center"><%=objFile.Type%></td>

<td align="center"><%=objFile.DateCreated%></td>

<td align="center"><%=objFile.DateLastModified%></td>

</tr>

</table>

</center>

</body>

 

 

File객체를 이용할때 '사용 권한이 없습니다' 라는 에러메세지 뜰 때!!

 

폴더에 오른쪽 버튼 클릭 후 -> 공유 및 보안-> 보안 탭 선택하고->EveryOne계정 클릭후 밑에 모든 권한 체크!!

 

 

'ASP' 카테고리의 다른 글

폴더검색 fso  (0) 2013.10.24
asp 모든폼 갖고오기  (0) 2013.10.24
Dext sumnail 새창으로 메일 보기  (0) 2013.10.24
새창 프린트 새창으로 메일 보기  (0) 2013.10.24
form encoding 형식 변경  (0) 2013.10.24
Posted by 초보용
,