Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 6th, 2006, 02:37 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
Post Classic ASP: dump text file contents into array

The code below is reading text file and putting its lines into array.
After the code is executed, each item of the array will be one
line of the text file.

Code:
<% Option Explicit %>
<%
Function ReadTextFile(strFilePath)
	Dim objFSO, objFile, strAllFile
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFilePath)
	strAllFile = ""
	If Not(objFile.AtEndOfStream) Then
		strAllFile = objFile.ReadAll
	End If
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing
	
	strAllFile = Replace(strAllFile, Chr(13)&Chr(10), Chr(13))
	strAllFile = Replace(strAllFile, Chr(10)&Chr(13), Chr(13))
	ReadTextFile = Split(strAllFile, Chr(13))
End Function

'usage
Const FILE_NAME="myfile.txt"
Dim arrLines, x, curLine
Response.Write("reading file: " & FILE_NAME & "...<br />")
arrLines = ReadTextFile(Server.MapPath(FILE_NAME))
Response.Write("amount of lines: " & (UBound(arrLines)+1) & "<br />")
Response.Write("file contents:<hr />")
For x=0 To UBound(arrLines)
	curLine = arrLines(x)
	Response.Write("Line #" & (x+1) & " " & Server.HTMLEncode(curLine) & "<br />")
Next
Response.Write("<hr />")
%>


for questions or comments, post here.

Last edited by Shadow Wizard : November 6th, 2006 at 02:40 AM.

Reply With Quote
  #2  
Old November 6th, 2006, 09:58 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
You can do the same using

Code:
Function ReadTextFile(strFilePath)
	Dim objFSO, objFile, strAllFile, Counter
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFilePath)
	strAllFile = Array()
	Counter = 0
	Do While Not (objFile.AtEndOfStream)
		Redim Preserve strAllFile(Counter)
		strAllFile(Counter) = objFile.ReadLine
		Counter = Counter + 1
	Loop
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing
	
	ReadTextFile = strAllFile
End Function
__________________
CyberTechHelp

Reply With Quote
  #3  
Old November 7th, 2006, 12:49 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
I don't like the Redim Preserve - it's not efficient and "eat"
lots of memory.
one more thing, I stumbled on files that ReadLine didn't really
read one line but rather gave the whole file.. found the
problem was with weird line breaks in the file - different combination
of Line Feed and Carriage Return than what expected by vbscript.

Reply With Quote
  #4  
Old November 9th, 2006, 02:00 AM
digitaldxb digitaldxb is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 155 digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 1 m 48 sec
Reputation Power: 4
Send a message via Google Talk to digitaldxb
regarding reading a wav file

Quote:
Originally Posted by degsy
You can do the same using

Code:
Function ReadTextFile(strFilePath)
	Dim objFSO, objFile, strAllFile, Counter
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFilePath)
	strAllFile = Array()
	Counter = 0
	Do While Not (objFile.AtEndOfStream)
		Redim Preserve strAllFile(Counter)
		strAllFile(Counter) = objFile.ReadLine
		Counter = Counter + 1
	Loop
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing
	
	ReadTextFile = strAllFile
End Function


I am not able to read from this code , nothing happens with this its just shows the blank screen , is there antyhing to follow before you implement the script , where this sript will be storing the output and how i can see that.

Regards

Reply With Quote
  #5  
Old November 9th, 2006, 02:03 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
the code posted by Desgy is only function, it's won't show anything.
try executing the code I gave and put your wav file name as the
value of FILE_NAME.

Reply With Quote
  #6  
Old November 9th, 2006, 02:04 AM
digitaldxb digitaldxb is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 155 digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 1 m 48 sec
Reputation Power: 4
Send a message via Google Talk to digitaldxb
regarding wav file

Quote:
Originally Posted by Shadow Wizard
The code below is reading text file and putting its lines into array.
After the code is executed, each item of the array will be one
line of the text file.

Code:
<% Option Explicit %>
<%
Function ReadTextFile(strFilePath)
	Dim objFSO, objFile, strAllFile
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFilePath)
	strAllFile = ""
	If Not(objFile.AtEndOfStream) Then
		strAllFile = objFile.ReadAll
	End If
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing
	
	strAllFile = Replace(strAllFile, Chr(13)&Chr(10), Chr(13))
	strAllFile = Replace(strAllFile, Chr(10)&Chr(13), Chr(13))
	ReadTextFile = Split(strAllFile, Chr(13))
End Function

'usage
Const FILE_NAME="myfile.txt"
Dim arrLines, x, curLine
Response.Write("reading file: " & FILE_NAME & "...<br />")
arrLines = ReadTextFile(Server.MapPath(FILE_NAME))
Response.Write("amount of lines: " & (UBound(arrLines)+1) & "<br />")
Response.Write("file contents:<hr />")
For x=0 To UBound(arrLines)
	curLine = arrLines(x)
	Response.Write("Line #" & (x+1) & " " & Server.HTMLEncode(curLine) & "<br />")
Next
Response.Write("<hr />")
%>


for questions or comments, post here.


I am able to see the output displayed in the browser but two problem what i am facing is

its not taking the file located in my drive and displayed an error but if i copy the file into the same folder where script in my webserver it works !!

So, how to read the files located in my d drive in the server or any map drive in the server .

Secondly after reading this is it possible to use any loop or any function which find out certian value which i am looking into the wav file output text , ie say for example to know where the file is fully downloaded or ended i can read a tag "8880000" at each of the wav file i am getting with this i can know that wav file is complete and downloaded successfully.

Regards

Reply With Quote
  #7  
Old November 9th, 2006, 02:08 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
regarding your first question, give full path:
Code:
Const FILE_NAME="D:\MyFolder\myfile.wav"

then change this line:
Code:
arrLines = ReadTextFile(Server.MapPath(FILE_NAME))

to this:
Code:
arrLines = ReadTextFile(FILE_NAME)


regarding your second question, please reply in your own thread
with exact details of what you need.

Reply With Quote
  #8  
Old November 9th, 2006, 03:08 AM
digitaldxb digitaldxb is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 155 digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 1 m 48 sec
Reputation Power: 4
Send a message via Google Talk to digitaldxb
thanks What i did is changed this code from top
Dim FILE_NAME
FILE_NAME = StrFilePath ' Contains my file name full path

and changed as you suggested it worked
thanks!!
arrLines = ReadTextFile(FILE_NAME)

Reply With Quote
  #9  
Old November 9th, 2006, 03:10 AM
digitaldxb digitaldxb is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 155 digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 1 m 48 sec
Reputation Power: 4
Send a message via Google Talk to digitaldxb
one quick query is that this all scripts are not working with the Map drive do i need to use any file system object with this script to work.

Regards

Reply With Quote
  #10  
Old November 9th, 2006, 03:49 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
StrFilePath can be "I:\MyFolder\myfile.wav" where "I:" is the mapped
network drive.. it should work as long as there are proper permissions.
feel free to post in your own thread about how to analyze the file.

Reply With Quote
  #11  
Old November 9th, 2006, 04:10 AM
digitaldxb digitaldxb is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 155 digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level)digitaldxb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 1 m 48 sec
Reputation Power: 4
Send a message via Google Talk to digitaldxb
yes i tried the same , seems to be permission issue but don't know how to overcome this , since the administrator has full rights to this drive but not sure what is the issue.

but anyhow if i keep it in my local its working good , great help !!! thanks a lot 3 cheers for you.

Reply With Quote
  #12  
Old November 9th, 2006, 04:58 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)