Solved

VBScript Permissions error

Posted on 2011-02-22
14
347 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now