473,543 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ


Hi everybody...I would like to know if it is possible and how to work
with files in javascript.


Jul 23 '05 #1
2 1572

Giacomin Alan wrote:
I would like to know if it is possible and how to work
with files in javascript.

It depends on the environment you are using JavaScript in whether it is
possible and if so how it is possible.
For instance on Windows with J(ava)Script in a HTA, an ASP page or a
Windows Script Host file it is possible and there you can use the
Scripting.FileS ystemObject to read and write text files:
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/script56/html/FSOoriFileSyste mObject.asp>

With Opera (at least when tested here with Opera 7 and Sun Java 1.5)
when Java it is enabled you can use LiveConnect in pages loaded locally
(file: URL) to read and write files e.g. try

var path = location.pathna me;
var dir = path.substring( 0, path.lastIndexO f('/') + 1);
dir = dir.replace(/%20/g, ' ');
var newFileName = dir + 'test2005011701 .txt';

if (navigator.java Enabled() && typeof java != 'undefined') {
var fileWriter = new java.io.FileWri ter(newFileName );
fileWriter.writ e("Kibology for all.\r\nAll for Kibology.\r\n") ;
fileWriter.writ e("Written at " + new Date());
fileWriter.clos e();
window.open('fi le://' + newFileName);

Of course access to the local file system that way is not allowed when
the page with the script is loaded from a http: URL.
If you are asking about script in a HTML page usually loaded via HTTP in
a browser then for security reasons such a script is not allowed file
access to the local file system. In some browsers (IE/Win, Mozilla,
Safari 1.2, Opera 7.60 preview and 8.00 beta) you can however load XML
from the server, manipulate it and send it back to the server:
<http://jibbering.com/2002/4/httprequest.htm l>


Martin Honnen
Jul 23 '05 #2
"Giacomin Alan" <g.******@virgi lio.it> wrote in message
news:79******** *************** ***@posting.goo gle.com...
Hi everybody...I would like to know if it is possible and how to work
with files in javascript.

If the script host which is hosting your ECMAScript provides an object
that lets you manipulate the file system, then you can manipulate the
file system using JavaScript/JScript/ECMAScript.

Microsoft provides such an object. It can be used from script running in
an HTA, script running in HTML if that HTML is hosted on your local hard
disk (and you agree to let active content run in Windows XP Service Pack
2) and the Windows Script Host.

It is also available in IIS (which is also a script host) and can be
accessed from JScript there.

The object Microsoft uses is called the FileSystemObjec t (FSO for


It appears appears Gecko-based browsers (or at least Mozilla and
Firefox) can do this as well, although I am unsure of the restrictions
governing their ability to actually create and manipulate files
(obviously script loaded from the Internet can not do these things).
Creating a new file in Mozilla appears to involve something along the
lines of:

var newFile =
Components.clas ses['@mozilla.org/file/local;1'].createInstance (Components.int erfaces.nsILoca lFile);

This seems like a good place to start if you want to learn more: <url:
http://www.mozilla.org/scriptable/co...ts_object.html />

Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL"...
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now you have your ".cpp" files all ready, without any "#include" or "#define" in them. Let's assume that there's 2 source files in this project,...
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or JPG files. The problem as I see it - if you know the name of the file, you could download it off the server (currently we are using an HTTP/Get but...
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.