Thursday, October 30, 2014

how to read all filename from folder using ASP Vbscript

Read all filenames from folder using ASP Classic Vbscript

Sometimes you require to get a list of all the files name from a folder, I was thinking how it can be implemented, the solution is to used the interface and write a script in VBScript. There is a sample script which is build in ASP Vbscript will get the list of files on a Folder.

function GetFiles(pFolder, pPattern)
dim Filelist
set Filelist = Server.CreateObject("SCRIPTING.DICTIONARY")
dim Regex
set Regex = new RegExp
Regex.IgnoreCase = true
Regex.Pattern = pPattern
dim Fso
set Fso = Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
dim Folder
set Folder = Fso.GetFolder(Server.MapPath(pFolder))
dim File
for each File in Folder.Files
if Regex.Test(File.Name) then
Filelist.add File.Name, Array(File.Type, File.Size, File.DateLastModified)
end if
next
set File = nothing
set Folder = nothing
set Fso = nothing
set Regex = nothing
set GetFiles = Filelist
end function
dim Files
set Files = GetFiles("agencies", "\.(asp|gif|jpg|jpeg|png|tif)$")
if Files.Count = 0 then
Response.write "There are no images to display. "
end if
dim Filename
for each Filename in Files
Response.write Filename
Response.write Files(Filename)(0)
Response.write Files(Filename)(1)
Response.writeFiles(Filename)(2)
next
How To Generate Random String Using ASP Classic vb script, Sql

Generate Random String Using ASP Classic VB script, Sql

Simple and highly customizable function so that you can generate random strings using VBScript that you can use in your ASP/VBScript applications. The random strings can be used for various purposes: Referral Codes, Promotional Codes, Random password for new registrations

function GetRefID(Val)
tot_unique=8
rid = ""
redim random_letter(tot_unique)
randomize
For counter = 1 to tot_unique
random_number = Int(26 * Rnd + 97)
random_letter(counter) = Chr(random_number)
'response.write random_letter(counter)
for check=1 to counter-1
if random_letter(check)= random_letter(counter) then
counter=counter-1
end if
next
next
For counter = 1 to tot_unique
'response.write "
  • " & random_letter(counter) & "
  • "
    rid=rid & random_letter(counter)
    next
    Userid= Val & rid
    Sql="Select id from tbl Where id ='"&Userid&"' "
    Set Rs = objcon.execute(Sql)
    IF Not Rs.eof then
    GetRefID()
    Else
    GetRefID= Userid
    End IF
    Rs.close()
    Set Rs = Nothing
    End Function