Scripting the File System, Part I: FileExists() through GetBaseName() - Doc JavaScript
Scripting the File System, Part I
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()
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: November 20, 2000
Revised: November 20, 2000
URL: https://www.webreference.com/js/column71/5.html