본문 바로가기

others

WScript.Network 이용해서 네트워크상의 파일정보 가져오기

별것 아닌건데 찾아서 적용시키는데 생각보다 오래 걸렸다..

WSH에 대해선 MSDN에도 삐리리하게 나와 있는듯...

아님 내가 못찾은건가?


<%
Option Explicit
'------------------------------------------------------------------------------------------
'  PROGRAM ID  : SearchFiles.asp
'  DESCRIPTION  : SearchFileName
'  AUTHOR    : lee young hwan
'  CREATE DATE  : 2005-05-18
'------------------------------------------------------------------------------------------

Dim Fso, FolderInfo
Dim SubFolders, SubFolder, SubFolderName
Dim Files, File, FileSize, ViewSize, ViewUnit
Dim RootFolder, StartFolder, TopFolder
Dim HighFolders, HighFolder, i
Dim WshNetwork

Set WshNetwork=Server.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "Z:", "\\contents\d$", false, "contents\administrator", "password"

'Response.End


StartFolder=Request("StartFolder")

RootFolder="//contents/d$/Contents/"
'RootFolder="D:/Contents/"


If Len(StartFolder)>0 Then
  TopFolder=RootFolder&StartFolder
  HighFolders=Split(StartFolder,"/",-1)
 
  For i=0 To Ubound(HighFolders)-1
    If i=0 Then
 HighFolder=HighFolders(i)
 Else
 HighFolder=HighFolder & "/" & HighFolders(i)
 End If
  Next

Else
TopFolder=RootFolder
End If

'Response.Write "TopFolder : "&TopFolder&"<br>"
'Response.Write "HighFolder : "&HighFolder&"<hr>"


%>
<html>
<head>
<title>초기파일명찾기</title>
<link href="/images/style_pop.css" rel="stylesheet" type="text/css">   
<script language="javascript">

function SubmitStartFolder(StartFolder){
 document.form1.StartFolder.value=StartFolder;
 document.form1.submit();
}

function SelectFileName(FileName){
 if (confirm(FileName+" 파일을 선택하시겠습니까?")){
 window.opener.frm.loadpage_.value=FileName;
 window.close();
 }
}

</script>
</head>

<body>
<form name="form1" method="post">
<input type="hidden" name="StartFolder">
</form>

<table width="410" border="0">
 <tr>
  <td height="30" style="border-bottom: #E0E0E0 2px solid;"><b>● 초기파일명찾기</b></td>
 </tr>
 <tr>
  <td style="border-bottom: #E0E0E0 1px solid;">현재폴더위치 :
  <%
   If Len(StartFolder) > 0 Then
    Response.Write "/"&StartFolder
   Else
    Response.Write "/"
   End If
  %>
  </td>
 </tr>
</table>

<table width="400" border="0">
 <tr>
<!-- right folder section -->  
  <td valign="top">
<%
Set Fso=CreateObject("Scripting.FileSystemObject")
Set FolderInfo=Fso.GetFolder(TopFolder)

'하위 폴더명을 가져온다.
Set SubFolders = FolderInfo.SubFolders
%>
   <table width="100" border="0" cellpadding="2" cellspacing="1">
    <tr >
     <td><li>폴더목록</li></td>
    </tr>
   </table>
   <table width="100" border="0" cellpadding="2" cellspacing="1" bgcolor="#B3B3B3">
    <tr bgcolor="#FFFFFF">
     <td><a href="javascript:SubmitStartFolder('<%=HighFolder%>')">..</a></td>
    </tr>
<%
For Each SubFolder In SubFolders
 If Len(StartFolder)>0 Then
  SubFolderName=StartFolder&"/"&SubFolder.name
 Else
  SubFolderName=SubFolder.name
 End If
%>
    <tr bgcolor="#FFFFFF">
     <td><a href="javascript:SubmitStartFolder('<%=SubFolderName%>')"><%=SubFolder.name%></a></td>
    </tr>
<%
Next
%>
   </table>
  </td>
<!-- left folder section -->
  <td  valign="top">
<%
Set Files = FolderInfo.Files
%>
   <table width="300" border="0" cellpadding="2" cellspacing="1">
    <tr >
     <td><li>파일목록</li></td>
     <td align="right"><input type="button" value="닫기" style="cursor:hand" onClick="javascript:window.close();"></td>
    </tr>
   </table>
   <table width="300" border="0" cellpadding="2" cellspacing="1" bgcolor="#B3B3B3">
    <tr bgcolor="#D5D5D5">
     <td>이름</td>
     <td>파일크기</td>
     <td>수정한날짜</td>
    </tr>
<%
If Files.Count>0 Then
 For Each File In Files
 
  FileSize=CLng(File.Size)
    ViewSize=Abs(FileSize/1024)
    ViewUnit="KB"
   
    If CInt(FileSize/1024/1024)>1 Then
     ViewSize=Abs(FileSize/1024/1024)
     ViewUnit="MB"
    End If
%>
    <tr bgcolor="#FFFFFF">
     <td>
<%  
   If Len(StartFolder)>0 Then
%>
     <a href="javascript:SelectFileName('<%="/course_data/"&StartFolder&"/"&File.name%>')"><%=File.name%></a>
<%
   Else
%>
     <a href="javascript:SelectFileName('<%="/Course_Data/"&File.name%>')"><%=File.name%></a>
<%
   End If
%>    
     </td>
     <td><%=Round(ViewSize, 1)&ViewUnit%></td>
     <td><%=FormatDateTime(File.DateLastModified, 2)%></td>
    </tr>
<%  

 Next
Else
%>
    <tr bgcolor="#FFFFFF">
     <td colspan="3" align="center">파일이 존재하지 않습니다.</td>
    </tr>
<%
End If
%>
   </table>
  </td>
 </tr>
</table>
 </body>
 </html>
<%
Set Fso=Nothing
WshNetwork.RemoveNetworkDrive "Z:"
Set WshNetwork=Nothing
%>

'others' 카테고리의 다른 글

motion graphic  (0) 2005.08.17
ASP 500 Error 처리 페이지  (0) 2005.06.08
ASP+ORACLE  (0) 2005.02.01
테이블 한줄에 3개씩 들어가게 만들기  (0) 2004.08.30
Fso를 이용한 메일보내기 소스  (0) 2004.08.03