File system manipulation, such as copying files and folders, requires the use of the File System Object (FSO). The following scripts demonstrate the use of the FSO to copy both files and folders.

Copying Files

The following scripts demonstrate how to copy a file from one local folder to another. In the first step, the script creates a File System Object. The CopyFile method, a file system object method, performs the file copy operation. The CopyFile method takes two parameters, the source file and the destination.

 CopyCode imageCopy Code
// JScript.
var FSO = WScript.CreateObject("Scripting.FileSystemObject");
FSO.CopyFile("c:\\COMPlusLog.txt", "c:\\x\\");

' VBScript.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "c:\COMPlusLog.txt", "c:\x\"

Copying Folders

The following script demonstrates how to copy the contents of one local folder to another folder on the local machine.

NoteNote

The destination folder must already exist for this method to succeed. For information on how to create a directory using WSH, see CreateFolder Method.

In the first step, the script creates a File System Object. The CopyFolder method, a file system object method, performs the folder copy operation. The CopyFolder method takes two parameters, the source folder and the destination.

 CopyCode imageCopy Code
// JScript.
var FSO = WScript.CreateObject("Scripting.FileSystemObject");
FSO.CopyFolder("c:\\x", "c:\\y");

' VBScript.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFolder "c:\x", "c:\y"

See Also

In Vbsedit, you only need to press F1 to get Help for the keyword under the cursor!


Download Now!



Download   Home  

Copyright © 2001-2024 adersοft