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?

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