Scripting the File System, Part I: Build() through CreateFolder() - Doc JavaScript | WebReference

Scripting the File System, Part I: Build() through CreateFolder() - Doc JavaScript


Scripting the File System, Part I

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()

https://www.internet.com


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