Article ID: 941190
You try to use the following code to copy the contents of a specific folder to a destination folder that contains a read-only file:
Note In this code, source_folder represents the actual source folder name, and destination_folder represents the actual destination folder name.When you run this code, you receive the following error message in the Windows Script Host dialog box:
This behavior is expected. Typically, you receive a "Permission Denied" error message when the filesystemobject.copyfolder method encounters a read-only destination file. However, you can drag a file to a folder that contains a read-only file of the same name. In this case, you receive the following message in Windows Explorer:
Error: Permission Denied
Source: Microsoft VBScript runtime error
This issue occurs because of a limitation in the CopyFolder method. The CopyFolder method cannot overwrite a file in the destination folder if the file has the read-only attribute set. The CopyFile method has this same limitation.
To resolve this issue, use the XCOPY utility together with the /R switch to overwrite any read-only files. The following code example shows one way to use the XCOPY utility to do this.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
In this code example, the /R switch enables the overwriting of read-only files. The /Y switch suppresses the prompt to confirm that you want to overwrite the existing destination file.
Contact us for more help
Connect with Answer Desk for expert help.