Solved

VBScript Permissions error

Posted on 2011-02-22
14
352 Views
Last Modified: 2012-05-11
Hi...I have a VB Script that is used to delete files after a certain amount of days have gone by.  Currently it is at 5 days.  I think it is a permissions problem but I've given that drive, folder, subfolders, child objects, etc....full permissions to everyone and anyone possible.  Yet when I run the script, it gives me a Permission Denied error on Line 16, Char 10.  Which is the fso.delete command.  I have attached an image of the error and the vb script text is pasted below:

vberror
Dim fso, startFolder, OlderThanDate
 
Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "F:\backups" ' folder to start deleting (subfolders will also be cleaned)
OlderThanDate = DateAdd("d", -5, Date)  ' 5days (adjust as necessary)
 
DeleteOldFiles startFolder, OlderThanDate
 
Function DeleteOldFiles(folderName, BeforeDate)
   Dim folder, file, fileCollection, folderCollection, subFolder
 
   Set folder = fso.GetFolder(folderName)
   Set fileCollection = folder.Files
   For Each file In fileCollection
      If file.DateLastAccessed < BeforeDate Then
         fso.DeleteFile(file.Path)
      End If
   Next
 
    Set folderCollection = folder.SubFolders
    For Each subFolder In folderCollection
       DeleteOldFiles subFolder.Path, BeforeDate
    Next
End Function


Thanks in  advance for your help.
0
Comment
Question by:ryan_johnston
14 Comments
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34953716
I should add that I have this same script on multiple servers on different domains and get the same error.  Also, if theres a better/easier script that will accomplish this, then I am open to suggestions.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34953816
Hi,

Can you add the following line at top of code, to confirm if issue with one file or all files

On Error Resume Next
0
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34953834
I didn't get the error that time when I added that line but nothing was deleted.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:prashanthd
ID: 34954210
Can you check if you are able to manually delete any of the files?
0
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34954406
Interesting...I used to be able to...now I cannot.  That makes me think it's definitely a permissions problem but I'm logged in as admin and Everyone, Administrators, Domain Admins, Domain Users, and Users have full control.  There are no deny entries in the permissions and the owner is administrator.
0
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34954433
I can create a new folder in that same directory and then delete it just fine.  Does Backup Exec put any kind of permissions on those folders?
0
 
LVL 12

Assisted Solution

by:prashanthd
prashanthd earned 100 total points
ID: 34954543
You can use process explorer to check if the files are being used by any application

http://technet.microsoft.com/en-us/sysinternals/bb896653
0
 
LVL 8

Accepted Solution

by:
ryan_johnston earned 0 total points
ID: 34954877
There wasn't anything keeping them open.  So on a whim I went and removed the drive from the device manager then went and unplugged the drive and plugged it back in.  I was now able to delete the files manually and the script worked as well without any errors.
0
 
LVL 13

Expert Comment

by:connectex
ID: 34958216
Try this for areas where the code could fail:


On Error Resume Next
objFile.Delete
If Err Then WScript.Echo sstrTest & "ERROR - " & Err.Description & ": " & objFile.Name & vblf
On Error GoTo 0

Open in new window

0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34960710
It is quite obvious that the files have been locked by an application/OS, for reasons unknown and my comments have helped to confirm the same, also there was never an issue with the script.

0
 
LVL 8

Author Comment

by:ryan_johnston
ID: 34962494
Yet the process explorer didn't show me anything that had them in use.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 34995591
Starting auto-close process to implement the recommendations of the participating Expert(s).
 
modus_operandi
EE Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question