폴더검색 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 초보용
,