accessing files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arie Zychlinski

    #1

    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: arie_zy@bezeqin t.net
    =============== =============== =============


  • kaeli

    #2
    Re: accessing files

    In article <3fd0b825@news. bezeqint.net>, arie_zy@bezeqin t.net
    enlightened us with...[color=blue]
    > 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 ?[/color]

    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?



    Comment

    • Laurent Bugnion, GalaSoft

      #3
      Re: accessing files

      Hi,

      Arie Zychlinski wrote:
      [color=blue]
      > 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.[/color]

      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 FileSystemObjec t, 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.Stri ng] strFullPath The file's full path.
      * @param [javascript.Stri ng] 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.saveT extFile = function( strFullPath, strContent, bOverwrite )
      {
      if ( ( navigator.appNa me != "Netscape" )
      && ( navigator.appNa me != "Microsoft Internet Explorer" ) )
      {
      alert( CExplorer.ALERT 001 );
      return;
      }

      if ( ( navigator.appNa me == "Netscape" )
      && ( parseFloat( navigator.appVe rsion ) >= 5 ) )
      {
      alert( CExplorer.ALERT 001 );
      return;
      }

      if ( navigator.platf orm.indexOf( "Win" ) == -1 )
      {
      alert( CExplorer.ALERT 003 );
      return;
      }

      if ( navigator.appNa me.indexOf( "Netscape" ) == -1 )
      {
      var fso = new ActiveXObject( "Scripting.File SystemObject" );

      if ( bOverwrite
      || !fso.FileExists ( strFullPath )
      || confirm( CExplorer.ALERT 002 ) )
      {
      var flOutput = fso.CreateTextF ile( strFullPath, true );
      flOutput.Write( strContent );
      flOutput.Close( );
      return true;
      }
      else
      {
      return false;
      }
      }
      else
      {
      netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
      "UniversalFileR ead" );

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

      if ( bOverwrite
      || !flCheck.exists ()
      || confirm( CExplorer.ALERT 002 ) )
      {
      netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
      "UniversalFileW rite" );
      var fsOutput = new java.io.FileOut putStream( strFullPath );
      var flOutput = new java.io.DataOut putStream( fsOutput );

      flOutput.writeB ytes( 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

      Comment

      Working...