Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing filenames into an Array help

Status
Not open for further replies.

girlinterrupted24

Programmer
Nov 16, 2005
35
ES
Hello there,

I don't know if I am on the right track at all... or whether what I want to do is possible... I basically would like to extract all filenames of files found in a folder, and to place these file names into an array... the orinal non dynamic version which works is this :

var theImageList = new Array(
// Name, URL
["Library image 1", "/images/library/1.jpg"],
["Library image 2", "/images/library/2.jpg"],
["Library image 2", "/images/library/3.jpg"]
);

This is what I have tried to do to make it dynamically extract all files found in folder, so these update automatically if files are added/deleted... but no luck as it doesn't work...

var fso = new ActiveXObject( 'Scripting.FileSystemObject' ),
e, f, i = [];
if( fso.FolderExists( 'c:\inetpub\ ) ) {
f = fso.GetFolder( 'c:\inetpub\ );
var tinyMCEImageList = new Array(
// Name, URL
e = new Enumerator(f.files);
for( ; !e.atEnd(); e.moveNext() ) {
if( ( i = e.item() ) ) { ["Library image " + i, i]; }
}

);
}

I would be ever so grateful for any help anyone could offer on getting this to work....Thank you
 
Hey again, thank you so much for keeping on with this and so sorry to be such a pain!!

I have tried both suggestions, which I must say I fully understand and makes absolute sense. Combining the ASP to get the files and then outputting the names to the js array...

The thing is for some reason it still does not seem to like it... I have this in the code now :

var tinyMCEImageList = new Array(
// Name, URL
["Library image 1", "/images/library/1.jpg"],
["Library image 2", "/images/library/2.jpg"],

<!-- All that needs outputing is ["Library image 1", "/images/library/1.jpg"], -->

<%
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Server.MapPath("/images/library/"))
Set fileList = objFiles.Files
For Each i In fileList
response.write ("[""" & i.name & """, ""/images/library/""" & i.name & """],")
next
%>
<!-- Leave empty one at the end (saves messing with the comma and falling over if there isnt any) -->
["", ""]
);

If I REMOVE the content within the ASP symbols <% %>, then it works fine, so it seems to not like the fact that I am swapping to ASP... essentially this is fed to the page as follows, as maybe I need to change this slightly, but I don't know to what...

The code above is saved in a file called "myexternallist.js"

Then this is brought into the content manager setup up as follows :

external_image_list_url : "tiny_mce/myexternallist.js",

And finally this is then called when the Insert image box is called like this :

var url = tinyMCE.getParam("external_image_list_url");
if (url != null) {
// Fix relative
if (url.charAt(0) != '/' && url.indexOf('://') == -1)
url = tinyMCE.documentBasePath + "/" + url;

document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
}




I did try the last suggestion also, saving this as a .asp file and trying to feed it in as a .asp file rather than a .js file as below, but this didnt work either...

external_image_list_url : "tiny_mce/myexternallist.asp",

I am so so sorry to keep bothering you with this, I am just desperate to get it to work!!

Thanks again,
Jayne
 
Your main page should have the asp code and will have to be named with the .asp extension. Your .js includes can remain as they are.

First though, it appears that you are using the javascript code to create the tinyMCEImageList array in Javascript. You cannot do this. ASP code will always execute before the javascript code so you would be writing the array content before the code to create the array object has been executed and even without having written the script tags.
In my example I create and populate the array all from ASP.

Do it like this:
<html>
<title></title>
<head>
<%
asp code in here to output the script opening tag, create the array object, populate the array object, close script tag.
%>

Do your .js file includes here
</head>
<body>
whatever you put in for HTML and calls to the javascript functions here.
</body>
</html>

Paranoid? ME?? Who wants to know????
 
In your Tiny MCE init function set

external_link_list_url : "example_link_list.asp",
external_image_list_url : "example_image_list.asp",
flash_external_list_url : "example_flash_list.asp"

and rename your file the same

extensions only state how a file is run not the contents
so tinymce is only looking for javascript text array

I currently have several systems running exactly what you are trying to do

ASP is run before javascript it calls the javascript function long after the asp has been proceesed and therefore its only a text file to your system.
 
I am seriously annoying myself let alone you, so sorry in advance for being a total pain in the .....

So... I have set the TINY MCE init function with

external_image_list_url : "tiny_mce/myexternallist.asp",

myexternallist.asp being the renamed js file which contains EXACTLY as below :

var tinyMCEImageList = new Array(
// Name, URL
["Library image 1", "/images/library/1.jpg"],
["Library image 2", "/images/library/2.jpg"],

<!-- All that needs outputing is ["Library image 1", "/images/library/1.jpg"], -->

<%
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Server.MapPath("/images/library/"))
Set fileList = objFiles.Files
For Each i In fileList
response.write ("[""" & i.name & """, ""/images/library/""" & i.name & """],")
next
%>
<!-- Leave empty one at the end (saves messing with the comma and falling over if there isnt any) -->
["", ""]
);

Where am I going wrong now, as you say you have it working so I am obviously doing something stupid!!

Thanks so much once again for being so helpful with this, it is so totally appreciated!!! :)

Jayne
 
Look at the HTML that your ASP code outputs and see if you can find the error there.

Lee
 
Where am I going wrong

You are using an HTMl-style comment in a JavaScript block. Not only that, you are using it in the middle of a statement.

Code:
var tinyMCEImageList = new Array(
    // Name, URL
     ["Library image 1", "/images/library/1.jpg"],
     ["Library image 2", "/images/library/2.jpg"],

    [!]<!-- All that needs outputing is ["Library image 1", "/images/library/1.jpg"], -->[/!]

Try removing it and see what happens.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
[tt]
var tinyMCEImageList = new Array(
// Name, URL
["Library image 1", "/images/library/1.jpg"],
["Library image 2", "/images/library/2.jpg"],

[red]//[/red]<!-- All that needs outputing is ["Library image 1", "/images/library/1.jpg"], -->

<%
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Server.MapPath("/images/library/"))
Set fileList = objFiles.Files
For Each i In fileList
[red]'[/red]response.write ("[""" & i.name & """, ""/images/library/""" & i.name & """],")
response.write ("[""Library image " & left(i.name,len(i)-4) & """, ""/images/library/" & i.name & """],")
next
%>
[red]//[/red]<!-- Leave empty one at the end (saves messing with the comma and falling over if there isnt any) -->
["", ""]
);
[/tt]
 
I just want to say an absolutely HUGE HUGE thank you to everyone for all your help with this. My lack of JS capability, and quite frankly JS stupidity, has annoyed me greatly with this - so all the patience you all have had in helping me get this to work is so so so much appreciated.

It is all working perfect now, so yeah - thank you so so much.

Jayne
 
Me again... I hear you go "nooo" ;)

This is probably the wrong place to ask, but you guys really seem to know your stuff with both JS and ASP stuff... and this is basically a general question to see if you have any suggestions as it is something nobody has ever seemed to offer any alternative to...

I am essentially looking for some form of auto-FTP via ASP... I have a version of code which does Auto-Upload via FTP from an ASP page from one server where it is running, to another server for which I set the FTP connection details in the code. The problem I have is this works absolutely perfect on my windows testing server, but then as soon as this is uploaded to the commercial server I use, due to the fact that this uses CMD.exe this is not permitted.... So I just wondered if you guys know of another way I can do this which doesn't require non-permitted features on commercial servers? I am basically hoping to achieve this to save allow a website update another website when I add information to it, without the need to have to manually upload the files to the other site separately via an FTP program.

Sorry, yet again to be bothering you, but just thought I would check, please dont worry if you dont, as I still so totally grateful for all your help so far on my other problem.

Ah, before I post! You may want to see my code for this, I will paste this below. Thank you ever so much again

Jayne

Code :

Set oScript = Server.CreateObject("WSCRIPT.SHELL")
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Build our ftp-commands file
Set objTextFile = objFSO.CreateTextFile(Path & "\" & portal_number & "\test.ftp")
objTextFile.WriteLine "lcd " & Path & "\" & portal_number & "\"
objTextFile.WriteLine "open " & ftp_address
objTextFile.WriteLine ftp_username
objTextFile.WriteLine ftp_password

' Check to see if we need to issue a 'cd' command
If ftp_remote_directory <> "" Then
objTextFile.WriteLine "cd " & ftp_remote_directory
End If

objTextFile.WriteLine "prompt"
objTextFile.WriteLine "mput *.*"
objTextFile.WriteLine "bye"
objTextFile.Close
Set objTextFile = Nothing
' Use cmd.exe to run ftp.exe, parsing our newly created command file
strCMD = "ftp.exe -s:" & Path & "\" & portal_number & "\test.ftp"
strTempFile = "C:\" & oFileSys.GetTempName( )
' Pipe output from cmd.exe to a temporary file (Not :|)
Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)
Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)

' Grab output from temporary file
strCommandResult = Server.HTMLEncode( oFile.ReadAll )
oFile.Close
' Delete the temporary & ftp-command files
' Call oFileSys.DeleteFile( strTempFile, True )
Call objFSO.DeleteFile(Path & "\" & portal_number & "\test.ftp", True)
 
Hi

Check with your host to see if you can run
objShell.Exec

If not ask if you can have them install compnents for you and what components they has set up already.

I used a method previously that uses say telnet commends, I will keep looking and post if nobody else replies.

D :eek:)
 
Are you sure the problem is with CMD.EXE? It could be you do not have rights to WSCRIPT.SHELL. I believe that XP and possibly Win 2003 have locked down shell access from IIS and they may have to open it up for you.



It's hard to think outside the box when I'm trapped in a cubicle.
 
Here is a quick way to test if shell is working.
Save this code as an ASP file and run it from the server.
It executes a ping and writes the response back to the browser. The ping has nothing to do with your issue but if you do not have shell capability the script will not return data to the screen....

Code:
<% Response.Buffer = true %> 
<% 
    url = "[URL unfurl="true"]www.espn.com"[/URL] 
 
    Set objWShell = CreateObject("WScript.Shell") 
    Set objCmd = objWShell.Exec("ping " & url) 
    strPResult = objCmd.StdOut.Readall() 
    set objCmd = nothing: Set objWShell = nothing 
 
    strStatus = "offline" 
    if InStr(strPResult,"TTL=")>0 then strStatus = "online" 
 
    response.write url & " is " & strStatus 
    response.write ".<br>" & replace(strPResult,vbCrLf,"<br>") 
%>

It's hard to think outside the box when I'm trapped in a cubicle.
 
Hi J

Just noticed in your script that you are trying to use CMD.EXE
Shouldnt this be FTP.EXE???

Das

Cant see any hosting company giving you command access to there servers.
 
Hey guys,

Thanks again for helping :) I tried that code to see if I actually have access to shell, and it errored so it seems it doesn't have access to that regardless of cmd.exe

At the time I wrote to the server and showed them the code and they just said they do not give access to cmd.exe and never will.

Das, in the script you say Im trying to use "cmd.exe" I guess I built this based on some other code I found on another site, so just copied that from there, I will now try it changing "cmd.exe" to "ftp.exe", see if it still works on my server, and if it does, then I will ask the commercial server I host websites with if they would grant me permission to shell at least, then that should do it. Will try all that now.

Will also check out that link you sent and if the above doesnt work, will see if there is anything else on there I may try.

Thanks so much again for your help
Jayne
 
Me again,

I seem to be still having problems with this method!! The link you included was however really informative actually! I have got it setup and it all makes sense, but cant get it to work, I then adapted my version with the code from the new version, not having the cmd.exe bit, but then it just doesnt work, not only that i popped the cmd.exe line back in to my modified version and that still doesnt work either so some change Ive made somewhere is throwing it out as I did have it working before on my original version, even though that of course is no good for commercial servers as it was!!

Anyway sadly I have to get some other work done so will go back to this as soon as I can, as it is VERY VERY much frustrating me as I really want to get it working!! Das, did you mention you had another version I could try, via Telnet? If you do could you post that on for me so I can try that, as yeah, although I dont have time really, I really want to get this working ... dog with a bone i think!!! :)

Thanks so much as always, Jayne
 
The problem is not really with CMD.EXE, but with the WSCRIPT.SHELL object.
Two things have to be true for this to work.
1. C:\winnt\system32\wshom.ocx has to be registered on the server for WSCRIPT.SHELL to be functional. This is registered by default but is sometimes intentionally disabled for security reasons.

2. CMD.EXE must be in the path for the server. This is also set in the path by default but might have been taken out for security reasons.

You do not need to be able to execute CMD.EXE yourself that would be a major security issue, rather the wshom.ocx file has to be able to execute cmd.exe with local rights and if the file is not in the path the execution fails. Neither of the two above requirements are anything you can change, they have to be done by the server administrator.

Since my PING script did not work then either the wshom.ocx file is not registered or cmd.exe is not in the path. Probably the former.
So the admin will have to give you the ability to run wscript.shell or you will have to find another way to do the FTP.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Hi J

I have had a look through previous scripts and found that the telnet commands was used in a php script, All other FTP related scripts in ASP use specific components that were installed on the servers.

It is worth calling your hosting company and letting them know what you are trying to achieve as it looks that your configuration is maybe abit to secure :-(.

Sorry cant help this time.
Das

Glad you fixed the TinyMCE Issue though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top