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.
Copy 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.
Note |
---|
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.
Copy 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" |