spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column71


Scripting the File System, Part I

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Build() through CreateFolder()

BuildPath(path, name)String

This method appends a name to a given path. A delimiter is added automatically. The following script will pop up the alert window below:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newpath = fso.BuildPath("c:\\tmp", "kuku.txt");
alert(newpath);
-->
</SCRIPT>

CopyFile(source, destination, overwriteFlag)Undefined

This method copies a source file to a destination file. If the destination file exists, it is overwritten only when overwriteFlag is true. On some systems, the destination file cannot be overwritten no matter what. Here is a script that copies test.txt from f:\ to f:\yehuda:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newpath = fso.CopyFile("f:\\test.txt", "f:\\yehuda\\test.txt");
-->
</SCRIPT>

CopyFolder(source, destination, overwriteFlag)Undefined

This method copies a source folder to a destination folder. If the destination folder exists, it is overwritten only when overwriteFlag is true. On some systems, the destination folder cannot be overwritten no matter what. Here is a script that copies temp from f:\ to f:\yehuda:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder("f:\\temp", "f:\\yehuda\\temp");
-->
</SCRIPT>

CreateFolder(folderName)String

This method creates a folder called folderName. It returns the folder name. Here is a script that creates a folder new:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newFolderName = fso.CreateFolder("f:\\new");
-->
</SCRIPT>

Next: How to use CreateTextFile() through DriveExists()

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: November 20, 2000
Revised: November 20, 2000

URL: http://www.webreference.com/js/column71/3.html