473,606 Members | 2,200 Online
Bytes | Software Development & Data Engineering Community
+ 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 1579


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://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
<http://jibbering.com/2002/4/httprequest.htm l>

--

Martin Honnen
http://JavaScript.FAQTs.com/
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
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.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

2
14159
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
0
6109
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" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
18
3159
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, "a.cpp" and
18
2285
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 I'm going to be using WebClient in the new version.) If there any way to password protect the...
3
5175
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
8439
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8430
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8305
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5966
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3930
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
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
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1296
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.