473,387 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

accessing files

I am thinking of using javascript as a tool to be used in a local PC (quick
development).
I would like to know if there is a way to read/write files from the local HD
(eg: read, write)
if not, is there any tool that can be used ?
thank you.

--

yours -
Arie Z.

============================================
Arie Zychlinski
R&D Consulting & Development
P.O.Box 536
Kfar-Saba 44104
ISRAEL

Mobile: 972-58-320230
Phone: W: 972-9-7673074 H: 972-9-7658268

E-Mail: ar*****@bezeqint.net
===========================================
Jul 20 '05 #1
2 5617
In article <3f******@news.bezeqint.net>, ar*****@bezeqint.net
enlightened us with...
I am thinking of using javascript as a tool to be used in a local PC (quick
development).
I would like to know if there is a way to read/write files from the local HD
(eg: read, write)
if not, is there any tool that can be used ?


Windows Script Host (WSH) and an HTA would work for reading and writing
client-side files. Assuming you're running Windows...

--
--
~kaeli~
If a parsley farmer is sued, can they garnish his wages?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Hi,

Arie Zychlinski wrote:
I am thinking of using javascript as a tool to be used in a local PC (quick
development).
I would like to know if there is a way to read/write files from the local HD
(eg: read, write)
if not, is there any tool that can be used ?
thank you.


The problem with that is that there is no cross-compatible way to
read/write files. In other words, you must use other objects in IE than
in Mozilla.

Anyway, for IE, take a look at the FileSystemObject, it's the most
convenient way to read/write local files from a local application.

For Netscape, you can use the java.io classes, in other words use the
Java objects directly from JavaScript.

I add a method from my CExplorer class, which might help you to
understand better what I mean.

HTH,

Laurent

/**----------------------------------------------------------------------------
* Saves a text file to the specified path.
* If the file already exists, overwrites it without warning.
*
* @param [javascript.String] strFullPath The file's full path.
* @param [javascript.String] strContent The file's content.
* @param [boolean] bOverwrite If true, the file is overwritten
* without question if it exists. If false, the user must confirm
* the overwriting.
* @return [boolean] True if the file has been saved, false otherwise.
*/
CExplorer.saveTextFile = function( strFullPath, strContent, bOverwrite )
{
if ( ( navigator.appName != "Netscape" )
&& ( navigator.appName != "Microsoft Internet Explorer" ) )
{
alert( CExplorer.ALERT001 );
return;
}

if ( ( navigator.appName == "Netscape" )
&& ( parseFloat( navigator.appVersion ) >= 5 ) )
{
alert( CExplorer.ALERT001 );
return;
}

if ( navigator.platform.indexOf( "Win" ) == -1 )
{
alert( CExplorer.ALERT003 );
return;
}

if ( navigator.appName.indexOf( "Netscape" ) == -1 )
{
var fso = new ActiveXObject( "Scripting.FileSystemObject" );

if ( bOverwrite
|| !fso.FileExists( strFullPath )
|| confirm( CExplorer.ALERT002 ) )
{
var flOutput = fso.CreateTextFile( strFullPath, true );
flOutput.Write( strContent );
flOutput.Close();
return true;
}
else
{
return false;
}
}
else
{
netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileRead" );

var flCheck = new java.io.File( strFullPath );

if ( bOverwrite
|| !flCheck.exists()
|| confirm( CExplorer.ALERT002 ) )
{
netscape.security.PrivilegeManager.enablePrivilege (
"UniversalFileWrite" );
var fsOutput = new java.io.FileOutputStream( strFullPath );
var flOutput = new java.io.DataOutputStream( fsOutput );

flOutput.writeBytes( strContent );

flOutput.flush();
fsOutput.close();
return true;
}
else
{
return false;
}
}
}
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #3

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

Similar topics

36
by: Thomas | last post by:
after spending countless hours trying, i give up and hope to get some help in here. on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm trying to read a file from an UNC...
3
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different...
5
by: Paulos | last post by:
Hi Has anyone any experience of accessing .CSV files with ADO.NET and C#? All I want to do is open and read a number of them. I have search the help files, the MDSN and all the books I have...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
4
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
3
by: Gerhard | last post by:
I have an application that needs to be able to upload documents that can latter be accessed and opened by a hyperlink. I can do this easliy if I store the files in a subdirectory in the...
3
by: kosmodisk | last post by:
Hi, I'm having problem accessing javascript-created elements from opened window. This occurs only when I'm including another files in opened window, javascript or css. When I comment out...
1
by: leenadiwan | last post by:
Friends, Im having problem with accessing a JS file placed in another folder from a JSP popup. I tried all the following: <SCRIPT LANGUAGE="JavaScript1.1" ...
6
by: Adam McCormack | last post by:
Good morning, I hope I'm not repeating a post, but I did try to search for the topic before asking. I am trying to resolve an issue that has come up as a result of planned migration from a single...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.