Reputation: 543
I am using the following code to copy a file, and paste it to a new directory. Then I am trying to delete the old folder and all files within it like so:
Source = "\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\Tasks\" & Range("D" & ActiveCell.Row).Value & "\" & Range("H" & ActiveCell.Row).Value& "\" & Range("AB" & ActiveCell.Row).Value & "\log.txt"
Destination = "\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\Tasks\" & Range("D" & ActiveCell.Row).Value & "\" & Range("O" & ActiveCell.Row).Value & "\" & Range("AB" & ActiveCell.Row).Value & "\log.txt"
On Error Resume Next
SetAttr Source, vbNormal
FileCopy Source, Destination
On Error Resume Next
dir_name = "\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\Tasks\" & Range("D" & ActiveCell.Row).Value & "\" & Range("H" & ActiveCell.Row).Value & "\" & Range("AB" & ActiveCell.Row).Value & "\"
Dim fso11
Set fso11 = CreateObject("Scripting.FileSystemObject")
fso11.DeleteFolder dir_name
SetAttr Destination, vbHidden
No matter what I do the folder will not delete, only the file is getting deleted inside the folder. Please can someone show me what am I doing wrong?
Upvotes: 0
Views: 69
Reputation: 17637
If you're sure you want to delete everything, use the Kill()
method instead to remove all files, then the RmDir()
method to remove the empty folder.
On Error Resume Next
Kill dir_name & "*.*"
RmDir dir_name
Err.Clear '// Clear error if exists
On Error GoTo 0 '// Reset error handling
Upvotes: 1