spacer

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

home / experts / javascript / column71


Scripting the File System, Part I

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

FileExists() through GetBaseName()

FileExists(fileName)Boolean

This method checks whether a file fileName exists. It returns true if it exists, and false otherwise. Here is a script that checks if file old.txt exists:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
fileBool = fso.FileExists("d:\\old.txt");
-->
</SCRIPT>

FolderExists(folderName)Boolean

This method checks whether a folder folderName exists. It returns true if it exists, and false otherwise. Here is a script that checks if folder old exists:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
folderBool = fso.FolderExists("d:\\old");
-->
</SCRIPT>

GetAbsolutePathName(pathName)String

This method returns a complete path from the provided pathName. As it echoes back the provided path, the need for this method is not clear.

GetBaseName(pathName)Boolean

This method returns a string containing the base name of pathName, without any extension or path. The use of this method is in applications that need to assemble file names on the basis of another file. For example, an application can name its output file using the base name of the executable (myapp.exe) and a different extenstion (myapp.out). The following script should pop up an alert box with the string myapp:

<SCRIPT LANGUAGE="JavaScript">
<!--
var fso = new ActiveXObject("Scripting.FileSystemObject");
baseName = fso.GetBaseName("f:\\yehuda\\js\\tips\\myapp.exe");
-->
</SCRIPT>

Next: How to use GetDriveName() through GetSpecialFolder()

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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/5.html