473,468 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Files

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

Thanks.

**Alan**
Jul 23 '05 #1
2 1561


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.FileSystemObject to read and write text files:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/FSOoriFileSystemObject.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.pathname;
var dir = path.substring(0, path.lastIndexOf('/') + 1);
dir = dir.replace(/%20/g, ' ');
var newFileName = dir + 'test2005011701.txt';

if (navigator.javaEnabled() && typeof java != 'undefined') {
var fileWriter = new java.io.FileWriter(newFileName);
fileWriter.write("Kibology for all.\r\nAll for Kibology.\r\n");
fileWriter.write("Written at " + new Date());
fileWriter.close();
window.open('file://' + 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://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
<http://jibbering.com/2002/4/httprequest.html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
"Giacomin Alan" <g.******@virgilio.it> wrote in message
news:79**************************@posting.google.c om...
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 FileSystemObject (FSO for
short):

<url:
http://msdn.microsoft.com/library/en...FileSystem.asp
/>

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.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile );

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*****@agricoreunited.com>
comp.lang.javascript 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

2
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...
0
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...
18
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...
18
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...
3
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
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.