如何線上查詢本地機的檔案?

來源:互聯網
上載者:User

<html>

<head>

<title>隨風起舞之檔案查詢</title>
</head>

<body>
<p align="center" >
  <b><font face="宋體" color="red" size="5">
  星河影動之檔案查詢系統</font></b>
</p>
<hr>
<form method="POST" action="search.asp">
  <p><font color="green">請輸入要查詢的目錄文字:
  <input type="text" name="search_data" size="20">
  <input type="submit" value="查詢" name="B1">
  <input type="reset" value="重寫" name="B2"></font>
  </p>
</form>
<hr>
<p style="text-indent: 0; word-spacing: 0; line-height: 100%; margin: 0">
<font color="green">查詢結果:</font></p>

<%
data=request.form("search_data")

' 得到要查詢的檔案名稱所要包含的字串.
p=search_folder(data,"http://yup.go.163.com","c:\")

' 調用函數查詢目標查詢目錄下的所有子目錄(所有子樹).
%>

<script language="vbscript" RUNAT=SERVER>
' 目錄檢索函數.
function search_folder(search_data,v_path,c_path)
  dim file_system,cur_folder,sub_folders,sub_files
  if not isempty(search_data) and len(search_data)>0 then

' 確定查詢字串有效非空.
      set file_system=createobject("scripting.filesystemobject")

' 建立檔案系統對象.
      set cur_folder=file_system.getfolder(c_path)

  ' 建立建立目前的目錄對象.
      set sub_folders=cur_folder.subfolders

' 建立目前的目錄的子目錄對象集合.
      for each each_sub_folder in sub_folders

  ' 對子目錄集合進行遍曆.
          if each_sub_folder.attributes=16 then

      ' 確定子目錄的屬性為普通子目錄.
          sub_v_path=v_path&"/"&each_sub_folder.name
          sub_c_path=c_path&"\"&each_sub_folder.name

      ' 得到當前的子虛擬絕對路徑與真實絕對路徑.
            p=search_file(search_data,sub_v_path,sub_c_path)

        ' 調用檔案檢索函數對當前子目錄下的檔案進行字串匹配檢索.
            p=search_folder(search_data,sub_v_path,sub_c_path)

        ' 遞迴檢索當前子目錄的下一級目錄.
          end if
      next
      set each_sub_folder=nothing
      set sub_folders=nothing
      set cur_folder=nothing
      set file_system=nothing

  ' 清除伺服器端對象.
  end if
  end function

function search_file(search_data,v_path,c_path)
  dim file_system,sub_files,sub_file_v_path,sub_out_v_path

' 檔案匹配檢索函數.
  if not isempty(c_path) then

  ' 確認路徑不為空白.

    set file_system=createobject("scripting.filesystemobject")
    set cur_folder=file_system.getfolder(c_path)
    set sub_files=cur_folder.files

' 建立檢索目錄下的檔案對象集合.
    for each each_file in sub_files

' 遍曆檔案對象集合.
        if instr(each_file.name,search_data)<>0 then

    ' 匹配字串與檔案名稱.
            sub_file_v_path=v_path&"/"&each_file.name

        ' 建立可用連結,輸出匹配檔案.

            sub_out_v_path=Replace(sub_file_v_path," ","%20")

            ' 替換路徑及檔案名稱中出現的空格.
            response.write("<p><a href=" & sub_out_v_path & _
                        ">"&sub_file_v_path&"</a>")
        end if
    next
    set sub_out_v_path=nothing
    set sub_file_v_path=nothing
    set each_file=nothing
    set sub_files=nothing
    set file_system=nothing
  end if
end function
</script>

<hr>
</body></html>

[1]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.