Disco Stu
05-03-2010, 10:24 PM
Hi all,
I have a VBScript that will allow the user to specifiy a path and folder size in Kb.
The script will keep deleting files (The oldest file first) until the size of the folder is below the specified user size.
Example "DeleteOldFiles.vbs E:\backup 300000"
That example will delete files from the E:\backup folder until the folder is below 300Gb.
The script works great when there is a path specified, but when you specifiy the root of a drive, it returns with a Permission denied error if you have had the backup program create the files in the root of a drive.
Example "DeleteOldFiles.vbs E:\ 300000"
If you get some files and copy them onto an removeable external USB drive and run the command "DeleteOldFiles.vbs E:\ 300000" it works OK, and no permission denied errors.
Here is a copy of the script......
strOldestFile = ""
dtmOldestDate = Now
MyPath = WScript.Arguments(0)
MySize = WScript.Arguments(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(MyPath)
intFolderSize = Int((objFolder.Size / 1024) / 1024)
intMySize = Int(MySize)
Do While intFolderSize >= intMySize
' WScript.Echo intFolderSize
' WScript.Echo MySize
' WScript.Echo objFolder
Set colFiles = objFolder.Files
'need to loop and delete files until folder is below given size.
For Each objFile In colFiles
strFile = objFile.Path
dtmFileDate = objFile.DateLastModified
If dtmFileDate < dtmOldestDate Then
dtmOldestDate = dtmFileDate
strOldestFile = strFile
End If
Next
WScript.Echo strOldestFile
objFSO.DeleteFile (strOldestFile) '<---- Permission Denied error here.
strOldestFile = ""
dtmOldestDate = Now
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(MyPath)
intFolderSize = Int((objFolder.Size / 1024) / 1024)
Set colFiles = objFolder.Files
Loop
''''''''End Script''''''
I have checked the permissions on the files that get created by the backup program and administrator has full control and I am running the command from the administrator login.
I have allowed full controll to system and users, with no luck.
I have noticed that there are no permissions on the root of the removable USB drive that I used for testing, but there are permissions on the removable E Drive on the server where the permission denied error occures.
Any ideas are appreciated.
Cheers.
Disco Stu :)
I have a VBScript that will allow the user to specifiy a path and folder size in Kb.
The script will keep deleting files (The oldest file first) until the size of the folder is below the specified user size.
Example "DeleteOldFiles.vbs E:\backup 300000"
That example will delete files from the E:\backup folder until the folder is below 300Gb.
The script works great when there is a path specified, but when you specifiy the root of a drive, it returns with a Permission denied error if you have had the backup program create the files in the root of a drive.
Example "DeleteOldFiles.vbs E:\ 300000"
If you get some files and copy them onto an removeable external USB drive and run the command "DeleteOldFiles.vbs E:\ 300000" it works OK, and no permission denied errors.
Here is a copy of the script......
strOldestFile = ""
dtmOldestDate = Now
MyPath = WScript.Arguments(0)
MySize = WScript.Arguments(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(MyPath)
intFolderSize = Int((objFolder.Size / 1024) / 1024)
intMySize = Int(MySize)
Do While intFolderSize >= intMySize
' WScript.Echo intFolderSize
' WScript.Echo MySize
' WScript.Echo objFolder
Set colFiles = objFolder.Files
'need to loop and delete files until folder is below given size.
For Each objFile In colFiles
strFile = objFile.Path
dtmFileDate = objFile.DateLastModified
If dtmFileDate < dtmOldestDate Then
dtmOldestDate = dtmFileDate
strOldestFile = strFile
End If
Next
WScript.Echo strOldestFile
objFSO.DeleteFile (strOldestFile) '<---- Permission Denied error here.
strOldestFile = ""
dtmOldestDate = Now
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(MyPath)
intFolderSize = Int((objFolder.Size / 1024) / 1024)
Set colFiles = objFolder.Files
Loop
''''''''End Script''''''
I have checked the permissions on the files that get created by the backup program and administrator has full control and I am running the command from the administrator login.
I have allowed full controll to system and users, with no luck.
I have noticed that there are no permissions on the root of the removable USB drive that I used for testing, but there are permissions on the removable E Drive on the server where the permission denied error occures.
Any ideas are appreciated.
Cheers.
Disco Stu :)