LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-11-2011, 11:07 PM   #1
jeffwang66
LQ Newbie
 
Registered: Jan 2011
Posts: 16

Rep: Reputation: 0
A javascript code


Hi, guys:

I wrote a javascript to go through each file in a folder. However, it can only run on windows machine because linux does not support ActiveXObject . Is there someway to change it so that it can run on Linux machine? I have post the code below.


Thanks,



function loadfiles()

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



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



var path=document.location;



path=turnPath(path);




var folder=fso.GetFolder(path);

var filesEnum=new Enumerator(folder.Files);



for(;!filesEnum.atEnd();filesEnum.moveNext())

{



var filename=filesEnum.item().Name;
}
}
 
Old 02-13-2011, 08:36 AM   #2
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 2,756

Rep: Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767
Quote:
Originally Posted by jeffwang66 View Post
Is there someway to change it so that it can run on Linux machine?
Yes. You can do it with browser-specific Javascript, which will of course ask the user for permission. This related link will start you off:

http://www.mozilla.org/projects/secu.../per-file.html

And here's how TiddlyWiki does it:

http://stackoverflow.com/questions/1...system/1087257

Last edited by dugan; 02-13-2011 at 08:55 AM.
 
Old 02-13-2011, 09:01 AM   #3
BenCollver2
Member
 
Registered: Feb 2009
Distribution: Fedora
Posts: 76

Rep: Reputation: 32
In rhino it would go something like this.

var fo = new java.io.File(path);
var files = fo.listFiles();

Or if you want to get fancy, you can use CommonJS ala narwhal or node.

Last edited by BenCollver2; 02-13-2011 at 09:03 AM. Reason: s/,/;/
 
Old 02-13-2011, 03:34 PM   #4
jeffwang66
LQ Newbie
 
Registered: Jan 2011
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by BenCollver2 View Post
In rhino it would go something like this.

var fo = new java.io.File(path);
var files = fo.listFiles();

Or if you want to get fancy, you can use CommonJS ala narwhal or node.



Thanks for your reply. Is the code like this?


function loadfiles()

{

var path=document.location;




path=turnPath(path);


var fo = new java.io.File(path);
var files = fo.listFiles();

var filesEnum=new Enumerator(files);

for(;!filesEnum.atEnd();filesEnum.moveNext())

{



var filename=filesEnum.item().Name;
}
}
 
Old 02-14-2011, 07:23 AM   #5
BenCollver2
Member
 
Registered: Feb 2009
Distribution: Fedora
Posts: 76

Rep: Reputation: 32
It would be more like this:

var fo = new java.io.File(path);
var files = fo.listFiles();
var filename;
var i;

for (i = 0; i < files.length; i++) {
filename = files[i];
}
 
  


Reply

Tags
activex, javascript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] chromium loading extension with javascript code in it Tux Rules Linux - Software 1 12-04-2010 09:35 AM
Apache2 showing Javascript code? ToothlessRebel Linux - Server 2 04-09-2007 12:20 PM
insert JavaScript code from server mavgh1 Linux - General 3 03-29-2006 12:57 AM
Javascript code, what do you think? swatward General 2 05-18-2005 09:43 AM
Javascript Code doesnt work w/ firefox? swatward Programming 1 04-18-2005 06:54 PM


All times are GMT -5. The time now is 02:46 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration