I have trying to create a script in VBS to delete oversized folders but both the DeleteFolder and Size methods give a Permission Denied error even though I full access to the folder tree in question.
Anybody come across this behaviour before?
How are you running the script?
No fancy XML stuff just yetCode:cscript foobar.vbs![]()
Sorry, I meant are you running it as part of a scheduled task or logon script or something?
You may want to check that everything under the root folder is inheriting permissions or you have sufficient permissions. Also are you forcing the delete as it is set at false by default.
nope interactive while logged as admin. The folders were on a remote share if that makes any difference.Originally Posted by Jonno
The funning thing is though I could quite happily delete folders usins the RD /S batch command in a CMD sub shell.
I think the problem might be because the size and delete methods of a folder object cannot act on a folder more than 1 level deep.
You'd think the Microsoft programers could just make use of few recursive system calls![]()
Works recursively here. Could be read-only files somewhere in the tree? If so, use filesystemobject.deletefolder "foldername",true - the true forces deletion of read-only files.Originally Posted by NetworkGeezer
Manage to fix your problem? I've been a bit slow to spot this thread!
Dunno about VBS, but I've coded C++ apps in .net that bring up this error. It happens if you try to access things across UNC/mapped drives (.net has a pile of BS 'security' additions that prevent code being executed in this way unless you 'appease' the security -- what nonsense!).
If you're running it off a network, try copying it to a local machine, failing that check if its trying to do network file access.
@srochford
The force parameter worked but what I don't understand is why the same error comes up when you're just trying to find the folder size.
Read-only file blocking a recurisive delete but why what kind blocks directory sizing when you have admin priviliges.
@Friez
Code C++ in .net? You bad boy. You don't believe Microsoft that C# is speedy enough for everybody.
I've never learned C# as such. I've always coded in C++ mainly due to coding for mac, linux and windows (impossible in C#) but now and then I have to code for Windows specific thing.
I code games as a hobby, C# is FAR too clunky for serious development in that area.
If there are any sub-folders which you don't have permission to access (because the permissions are wrong) then this will fail.Originally Posted by NetworkGeezer
I'm not absolutely sure why this is but I'd guess the logic is this: when you want to know the size of a folder the OS has to open that folder to see what's inside it. If you're not allowed to open that folder then you won't be able to get the size of it and the only sensible message to return is "access denied" - because that's what it is!
Are these user home folders? If so, I'd guess a user has created a folder and then changed the permissions so that only they have rights. This might be for badness or just because they're experimenting :-)
What I'd guess you need to do is make sure that you have rights to every folder in the tree before you try to find the size of the folders.
Alright this isn't making any sense. The trouble seems to come if I try to For Each (iterate) through a subfolders collection. I get "Permission Denied" when trying to get folder size of each constituent folder.
But if I use a FOR /F to get the folders and then call the VBS script using the folder name as an argument, the Folder.Size call works.
This has been the problem all along. My access rights are OK using command line or batch script to do the task but not VBS
I am the domain admin for pity's sake. Gimme the blasted information you blasted annoying script engine.
any chance you can post the script along with the error or better yet a screen shot of the error the script gives you
I get the permission denied error at the WScript.Echo line unless I either delete or comment out the objSubfolder.size term.Code:objFSO = CreateObject("Scripting.FileSystemObject") objHomeRoot = objFSO.GetFolder("E:\\Student\\HomeFolders\Year" & WScript.Arguments(0)) For Each objSubFolder In objHomeRoot.SubFolders WScript.Echo "Folder " & objSubFolder.Name & " occupies " & objSubFolder.size & " bytes" Next
I have also tried a test in JScript but with the same result "Permission Denied"
Code:fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.GetFolder("E:\\Student\\HomeFolders\\Year7"); fc = new Enumerator(f.SubFolders) ; s = "" ; for (;!fc.atEnd(); fc.moveNext()) { WScript.Echo(fc.fc.item().size); };
But the it the .size member works if I do it outside a For Each loop. Now as there is no way of refering to the constituents of the SubFolders collection without knowing their names this means I have to feed the names using FOR /F command subsitution:
which callsCode:CD E:\Student\HomeFolders\Year7 & FOR /F %f in ('DIR /AD /B ') do cscript /NoLogo HomeSize.vbs %f
This works but why not enumarating through a subfolders collection using For Each?Code:objFSO = CreateObject ("Scripting.FileSystemObject") objHomeFolder = objFSO.GetFolder(WScript.Arguments(0)) WScript.Echo "Folder " & objHomeFolder.name & " consumes " & objHomeFolder.size
Aaargh!!! What is going on????
There are currently 1 users browsing this thread. (0 members and 1 guests)