List directory with specified extension & link

Contenu du snippet

Ce code permet de lister un repertoire en VBscript, il liste en focntion des extensions de fichiers spécifier, et les met en liens

Source / Exemple :


<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit 'Option Explicit requires that you declare all variables

Dim strDocsPath, strDocsPhysicalPath
Dim objFSO, objFolder, objFiles, objFile
Dim strName, strFile, strType, lngSize
Dim extension
' NOTE: set the following line to the folder to display
strDocsPath = "/[...]" 'NOTE: Change this setting to the folder in your directory that contains
                                                 'the files you want to list (directory web!!!)

' map the folder to a physical path
strDocsPhysicalPath = Server.MapPath(strDocsPath)

' create a system file object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

' create an object for the folder
Set objFolder = objFSO.GetFolder("C:\[...]")'Directory physic
' create a files collection
Set objFiles = objFolder.Files

' step through the files collection
For Each objFile in objFiles

' get a file's name
strName = objFile.Name

extension = objFSO.GetExtensionName(strName)
if extension = "html" then' remplacer html par les extensions que vous voulez

' make it lowercase for the URL
strFile = Lcase(strName)

' get the file's type
strType = objFile.Type

' make the name a title for display
strName = MakeTitle(strName)

' get the file size in KB
lngSize = objFile.Size\1024

' output the filename and URL
Response.Write "<li><a href= continue.asp?"& strFile & ">" & strName & "</a><br>"
'if you want to link to contine.asp?linkfile
' output the file's size and type
Response.Write "<em>(" & lngSize & "KB " & strType & ")</em></li>" & vbCrLf
end if
Next

' this function simply drops the extension from a file
Function MakeTitle(strTemp)
If InStrRev(strTemp,".") Then
strTemp = Left(strTemp,InStrRev(strTemp,".")-1)
End If
MakeTitle = strTemp
End Function
%>

Conclusion :


A vos commentaires !!!
Pour les détails:
http://lopez.thomas1.free.fr/Java ou http://javaetvous.new.fr/

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.