Permission Denied Error On objFile.Copy 
Author Message
 Permission Denied Error On objFile.Copy

I'm writing a script to copy multiple files and folders
from a mapped network drive to a local folder. Copying the
folders works great, no problem, and all their sub folders
and files carry over nicely.

However, for each and every file sitting at the top level
of the source folder, I get a "Permission Denied" error
and the file does not copy. I checked security settings
and I do have full control over the file and the source
drive.

Any thoughts?



Tue, 06 Dec 2005 22:20:40 GMT  
 Permission Denied Error On objFile.Copy
Can you send the part of the code that implements the logic?

Thanks

Sandeepan


Quote:
> I'm writing a script to copy multiple files and folders
> from a mapped network drive to a local folder. Copying the
> folders works great, no problem, and all their sub folders
> and files carry over nicely.

> However, for each and every file sitting at the top level
> of the source folder, I get a "Permission Denied" error
> and the file does not copy. I checked security settings
> and I do have full control over the file and the source
> drive.

> Any thoughts?



Thu, 08 Dec 2005 12:25:15 GMT  
 Permission Denied Error On objFile.Copy
Const strDriveToBackup = "N:"
' TO BACKUP ONLY A SPECIFIC FOLDER IN THE ABOVE DRIVE, PUT
THE FOLDER NAME ONLY HERE - OTHERWISE DO NOT CHANGE. FOR
INSTANCE,
'       IF YOU WANT TO BACK UP A FOLDER NAMED "Files", THE
LINE BELOW SHOULD READ: Const strFolderToBackup = "Files"
Const strFolderToBackup = ""

' CHANGE THE DRIVE AND FOLDER BELOW TO WHICHEVER LOCATION
YOU WANT THE BACKUP TO SAVE TO
Const strBackupLocation = "C:\HOME-DRIVE-BACKUP"
' ****************************** DO NOT CHANGE ANYTHING
BELOW THIS LINE ******************************

Dim objFSO
Dim objDriveRoot
Dim objFile
Dim objFolder

Call doBackup

Public Sub doBackup

        ' Create a refernece to the file system
        Set objFSO = CreateObject
("Scripting.FileSystemObject")

        ' Find out whether the user wants to backup a
specific folder, or the entire thing
        If strFolderToBackup <> "" Then ' The user is
backing up a folder within the drive

                ' Make sure that the system can detect the
drive/folder to back up
                If Not objFSO.FolderExists
(strDriveToBackup & "\" & strFolderToBackup) Then

                        MsgBox "The system cannot detect "
& strDriveToBackup & "\" & strFolderToBackup & ". The
backup cannot continue. Please check your network
settings.",vbExclamation,"Cannot Detect Drive"
                        Exit Sub

                Else

                        Set objDriveRoot = objFSO.GetFolder
(strDriveToBackup & "\" & strFolderToBackup)

                End If

        Else ' The user is just backing up a drive

                ' Make sure that the system can detect the
drive to back up
                If Not objFSO.DriveExists
(strDriveToBackup) Then

                        MsgBox "The system cannot detect
drive " & strDriveToBackup & ". The backup cannot
continue. Please check your network
settings.",vbExclamation,"Cannot Detect Drive"
                        Exit Sub

                Else

                        Set objNetwork = objFSO.GetDrive
(strDriveToBackup)
                        Set objDriveRoot = objFSO.GetFolder
(objNetwork.Path)

                End If

        End If

        ' Now we'll verify that the destination folder
actually exists - if it doesn't, we'll create it.
        On Error Resume Next
        If Not objFSO.FolderExists(strBackupLocation) Then

                objFSO.CreateFolder strBackupLocation

                If Err.Number <> 0 Then ' An error occured
trying to create the destination folder

                        MsgBox "An error occurred trying
to create " & strBackupLocation & ". Reason: " &
Err.Description & ".",vbExclamation,"Could Not Create
Destination"
                        Exit Sub

                End If

        End If
        On Error GoTo 0

        On Error Resume Next

        ' Backup folders
        For Each objFolder In objDriveRoot.SubFolders

                If Not objFSO.FolderExists
(strBackupLocation & "/" & objFolder.Name) Then

                        objFSO.CreateFolder
strBackupLocation & "/" & objFolder.Name

                End If

                objFolder.Copy strBackupLocation & "/" &
objFolder.Name

                If Err.Number <> 0 Then

                        MsgBox "Error copying " &
objFolder.Name & " to " & strBackupLocation & " for the
following reason: " & Err.Description & ". Backup will
continue.",,"Folder Could Not Copy"
                        Err.Clear

                End If

        Next

        '
***********************************************************
*****************
        ' BELOW IS WHERE I GET THE ERROR - FOR EACH AND
EVERY FILE IN THE SOURCE DRIVE
        '
***********************************************************
*****************

        For Each objFile In objDriveRoot.Files

                objFile.Copy strBackupLocation

                If Err.Number <> 0 Then

                        MsgBox "Error copying " &
objFile.Name & " to " & strBackupLocation & " for the
following reason: " & Err.Description & ". Backup will
continue.",,"File Could Not Copy"
                        Err.Clear

                End If

        Next

Quote:
>-----Original Message-----
>Can you send the part of the code that implements the
logic?

>Thanks

>Sandeepan



>> I'm writing a script to copy multiple files and folders
>> from a mapped network drive to a local folder. Copying
the
>> folders works great, no problem, and all their sub
folders
>> and files carry over nicely.

>> However, for each and every file sitting at the top
level
>> of the source folder, I get a "Permission Denied" error
>> and the file does not copy. I checked security settings
>> and I do have full control over the file and the source
>> drive.

>> Any thoughts?

>.



Fri, 09 Dec 2005 20:57:17 GMT  
 Permission Denied Error On objFile.Copy

I'm not too sure 'cause I'm new to this but I think that this might
work for you..

Try changing

       Const strBackupLocation = "C:\HOME-DRIVE-BACKUP"
to

       Const strBackupLocation = "C:\HOME-DRIVE-BACKUP\"

I think that you are just missing the last backslash

--
Posted via http://dbforums.com



Wed, 14 Dec 2005 10:10:53 GMT  
 Permission Denied Error On objFile.Copy
Did you put backslash at the end of the path? I was getting Permission
Denied too and I had to put backslash at the end

-Bindra



Sat, 17 Dec 2005 07:01:08 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Getting Permission Denied error, using FSO.Copy or InUse.exe

2. error 70 - permission denied when copying files

3. Can anyone help with a permission denied error when copying a file

4. Why error Error: Permission denied code 800A0046 on line 20 char 5

5. File copying -- Permission denied

6. Permission Denied when copying a file to the SendTo folder

7. Copy file over network : Permission Denied

8. Permission denied when copying a file

9. Error Number : 70 and Error Description : Permission Denied

10. Compile Error - Permission Denied (Error 70)

11. Permission denied when trying to copy over unregistered dll

12. Permission Denied(compile error) with opendatabase statement

 

 
Powered by phpBB® Forum Software