37 users online (1 members and 36 guests)  


  Results 1 to 6 of 6

Related

  1. xml file reading    Forum: Javascript Forum
    Replies: 0
  2. Why use index files in every directory?    Forum: HTML Forum
    Replies: 2
  3. Replies: 2
  4. Replies: 0
  5. Replies: 17
  1. #1
    jmehl84's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Posts
    3

    Counting files and Reading filenames from a specified directory in JS

    Hey -

    As a project for my JS class I'm trying to build a simple mp3 javascript player that will read x amount of mp3s from a directory that i specifiy where you can place x amount of songs w/o ever actually placing direct links to the files in the script.

    I know I'm not great at describing this, but basically I need an array that's a variable size based upon how many files in the directory, and a way for counting how many files. I've been searching for the right commands but so far have come across nothing that really fits what I'm looking for.

    Any and all help is appreciated.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Quick Answer: No. Not with JavaScript.

    You can just about do it using an ActiveX control, but these are not to be trusted, and a lot of people will not run them.

    Is this designed to be client-side or a webpage?

    If its a webpage, use a server-side language like PHP or ASP. No question about it. If you are making (by the sound of it) a client tool to be run on a local machine, then use activeX.

    Heres a sample activeX script, this one basically counts and lists all image files in a given folder. I am sure you can adapt it.

    Code:
    <SCRIPT>
    picturefile("C:\\Documents and Settings\\User\\My Documents\\My Pictures")
    function picturefile(thefolder){
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if(fso.folderExists(thefolder)){
        bbb=fso.GetFolder(thefolder)
        aaa=""
               oFileColl = new Enumerator(bbb.files);
             abc = new Array();
             i=0
    
               for (; !oFileColl.atEnd(); oFileColl.moveNext())
               {
                      tempp = new String(oFileColl.item());
                  if((tempp.indexOf(".gif")!=-1)||(tempp.indexOf(".jpg")!=-1)){
                       abc[i]=tempp
                       i++
                       aaa+=tempp+"\n"
                  }
                 }
    alert("There are "+i+" picture files in "+thefolder+"\n\nThey are:\n\n"+aaa)
    
    }
    }
    </SCRIPT>
    Never, never NEVER run an activeX script unless you have read it, you understand it, and you know what it does. Potentially and very easily I could write a script to remove those files and hide the command in a load of useless code. So be warned.

    For more info on the Object called above, see -
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsfsotutor.asp
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    jmehl84's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Posts
    3
    To answer your question, yes this is designed just to be client side.

    Thanks for the help with that... forgive me if the following question is somewhat dumb as I have very little experience with ActiveX, but can I use the variables that I define in activeX in a javascript on the same page?

    If I had to write the entire script in activeX I'd be in some trouble as I basically don't know it

    Thanks,

    Jeff

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Yes, all variables are accessible to JavaScript (the 'alert' is a javascript function).

    I don't have much experience of ActiveX either, just enough so I can figure out if a script is evil or not.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    jmehl84's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Posts
    3
    Thanks for the help, I figured out and plugged in the script yesterday.

    -Jeff

  6. #6
    siddikshaik's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2011
    Posts
    1

    Re: Counting files and Reading filenames from a specified directory in JS

    what is the parrallel way for the below code in firefox and Chrome

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    ActiveXObject is an IE Object