FSO ile klasör içeriğini listelemek » Anthony Burak Dursun

FSO ile klasör içeriğini listelemek

Bu yazı Tasarım ve Kodlama kategorisine 16.10.2010 Tarihinde Eklendi, 416 Kez Okundu.

ASP ile yapılabilecek bir çok şey var ve benim bunlardan en çok sevdiğim bir şey de bir explorer gibi dosyaları, klasörleri listeletmek. Yaptığım yazılımların bir çoğunda bu özelliği kullanırım.

En basitinden bir klasör içinde ki dosyaları nasıl listeleyeceğinizi gösterelim.

Bunun için listele.asp adlı bir dosya oluşturun. Bunun içerisine aşağıda ki kodu yazın:

<%
Set ObjFSO=Server.CreateObject("Scripting.FileSystemObject")
Set FSOFiles = ObjFSO.GetFolder(Server.MapPath("/"))    ´ Klasör Yolu

For each FSOFileList in FSOFiles.files
    Response.Write FSOFileList.Name & " ("& FSOFileList.size & " Byte) <br />"
Next
%>

En basit anlatımıyla yukarıda istediğiniz bir klasörün içini size boyutlarıyla listeleyen bir kod örneği verdim. Bunu geliştirip daha farklı uygulamalar yapabilirsiniz.

Mesela kendinize özel bir host alanı yaparak, biraz css, biraz javascript ile birebir Dosya Gezgini yaratabilirsiniz.

<style type="text/css">
<!--
body,td,th {
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 11px;
}
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style>

<%
Function BoyutHesapla(girdi)
     If girdi<1024 Then
          boyut = girdi & " byte"
     ElseIf (girdi < 1024*1024) Then
          boyut = FormatNumber(girdi/1024,2) & " KB"
     ElseIf (girdi < 1024*1024*1024) Then
          boyut = FormatNumber(girdi/(1024*1024),2) & " MB"
     ElseIf (girdi < 1024*1024*1024*1024) Then
          boyut = FormatNumber(girdi/(1024*1024*1024),2) & " GB"
     ElseIf (girdi < 1024*1024*1024*1024*1024) Then
          boyut = FormatNumber(girdi/(1024*1024*1024*1024),2) & " TB" ´Asla yaramaz
     End If
     BoyutHesapla=boyut
End Function
%>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="20" bgcolor="#F7F7F7"><strong>Dosya Adı</strong></td>
    <td bgcolor="#F7F7F7"><strong>Boyut</strong></td>
    <td bgcolor="#F7F7F7"><strong>Değiştirilme Zamanı</strong></td>
    <td bgcolor="#F7F7F7"><strong>İşlem</strong></td>
  </tr>
<%
Set ObjFSO=Server.CreateObject("Scripting.FileSystemObject")
Set FSOFiles = ObjFSO.GetFolder(Server.MapPath("/"))    ´ Klasör Yolu

For each FSOFileList in FSOFiles.files
%>
  <tr>
    <td height="20"><%=FSOFileList.Name%></td>
    <td><%=BoyutHesapla(FSOFileList.size)%></td>
    <td><%=FSOFileList.DateLastModified%></td>
    <td>sil | y&uuml;kle | d&uuml;zenle</td>
  </tr>
<%
Next
%>
</table>

Bu da size yol gösterecek basit bir örnek olabilir arkadaşlar.

FSO ile hangi işlemleri yapabilirsiniz aşağı da ki tablodan görebilirsiniz.

Property Description
Attributes Sets or returns the attributes of a specified file
DateCreated Returns the date and time when a specified file was created
DateLastAccessed Returns the date and time when a specified file was last accessed
DateLastModified Returns the date and time when a specified file was last modified
Drive Returns the drive letter of the drive where a specified file or folder resides
Name Sets or returns the name of a specified file
ParentFolder Returns the folder object for the parent of the specified file
Path Returns the path for a specified file
ShortName Returns the short name of a specified file (the 8.3 naming convention)
ShortPath Returns the short path of a specified file (the 8.3 naming convention)
Size Returns the size, in bytes, of a specified file
Type Returns the type of a specified file
Drives Returns a collection of all Drive objects on the computer
Method Description
Copy Copies a specified file from one location to another
Delete Deletes a specified file
Move Moves a specified file from one location to another
OpenAsTextStream  Opens a specified file and returns a TextStream object to access the file
BuildPath Appends a name to an existing path
CopyFile Copies one or more files from one location to another
CopyFolder Copies one or more folders from one location to another
CreateFolder Creates a new folder
CreateTextFile Creates a text file and returns a TextStream object that can be used to read from, or write to the file
DeleteFile Deletes one or more specified files
DeleteFolder Deletes one or more specified folders
DriveExists Checks if a specified drive exists
FileExists Checks if a specified file exists
FolderExists Checks if a specified folder exists
GetAbsolutePathName Returns the complete path from the root of the drive for the specified path
GetBaseName Returns the base name of a specified file or folder
GetDrive Returns a Drive object corresponding to the drive in a specified path
GetDriveName Returns the drive name of a specified path
GetExtensionName Returns the file extension name for the last component in a specified path
GetFile Returns a File object for a specified path
GetFileName Returns the file name or folder name for the last component in a specified path
GetFolder Returns a Folder object for a specified path
GetParentFolderName Returns the name of the parent folder of the last component in a specified path
GetSpecialFolder Returns the path to some of Windows´ special folders
GetTempName Returns a randomly generated temporary file or folder
MoveFile Moves one or more files from one location to another
MoveFolder Moves one or more folders from one location to another
OpenTextFile Opens a file and returns a TextStream object that can be used to access the file

Çılgın Dükkan | İlginç Hediyelik Ürünler

Etiketler:asp, fso, file system object, listeleme, dosya listeleme,