Microsoft VBScript runtime error Code 800A0046 line 49 , Char 1 "Permission denied"

Skip to first unread message

Jeffrey Smith

Jun 4, 2015, 12:00:21 PM6/4/15

I'm using a script to clear Temp files and folders developed by Michael Harris and posted at:!topic/microsoft.public.scripting.wsh/j7e2oL0F0pY

It has worked for me since I re-installed Windows 7 a couple of weeks ago but has suddenly started giving me this error:

Microsoft VBScript runtime error Code 800A0046 line 49 , Char 1 "Permission denied"

(Note: I had actually had this happen to me a few years back, so I don't know if this is an intermittent problem or what conditions make it happen)

This is the code (Note, too that I get the same error when I try to open Microsoft Windows Based Script Host, so this was opened with Notepad):

' Source:
'Michael Harris

Const TemporaryFolder = 2 'for GetSpecialFolder
set fso = createobject("scripting.filesystemobject")
'init an empty array (ubound will be -1)...
'we use an array and store the file objects.
'this avoids any problems with altering the
'contents of the Files collections while they
'are being iterated.
arFiles = array()
count = -1
'get the path to the temp folder
tempdir = fso.GetSpecialFolder(TemporaryFolder)
'load the (global scope) arFiles
'SelectFiles calls itself recursively
'for SubFolders
SelectFiles tempdir
msgbox count+1 & " files found"
'now do the actual deletes. the error trap
'is in case any are in-use...
dcount = 0
for each file in arFiles
on error resume next
file.delete true
if err.number = 0 then dcount = dcount + 1
on error goto 0
'now go back and delete empty folders
'below the temp folder
DeleteEmptyFolders tempdir,false
'comment out for "silent" operation,
'or add support for a "/s" command-line switch.
msgbox count+1 & " files found, " & dcount & " deleted."
sub SelectFiles(sPath)
'select files to delete and add to array...
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
count = count + 1
redim preserve arFiles(count)
set arFiles(count) = file
for each fldr in folder.subfolders
SelectFiles fldr.path
end sub
sub DeleteEmptyFolders(sPath,bDeleteThisFolder)
set folder = fso.getfolder(sPath)
'recurse first...
for each fldr in folder.subfolders
DeleteEmptyFolders fldr.path,true
'if no files or folders then delete...
'bDeleteThisFolder is false for
'the root of the subtree, and true for
'sub-folders (unless you want to delete
'the entire subtree if it is empty).
if (folder.files.count = 0) and _
(folder.subfolders.count) = 0 and _
bDeleteThisFolder then
exit sub
end if
end sub

I'd appreciate any insights.

Reply all
Reply to author
0 new messages