Just been trying to do something that I thought would be really simple. Just been modifying a script which checks a specified network drive’s folders, to make sure that every folder has a corresponding user in Active Directory, and then, if it does set the owner and permissions on that folder accordingly. (We have changed from using Home Folders in AD to using Folder Redirection, which only works when the user is the owner of their folder)
So, during testing I noticed that two folders kept coming up that I did not want to modify the permissions on; System Volume Information and $RECYCLE.BIN. Instant thought: If folder is not called ‘System Volume Information’ Or ‘$RECYCLE.BIN’ Then Run Code.
Translated into VBScript it looked something like this:
For Each objSubfolder in colSubfolders
If objSubfolder.Name <> "System Volume Information" And objSubfolder.Name <> "$RECYCLE.BIN" Then
Code to check goes here
End If
Could not get this to work at all. Even Microsoft Technet says that it should. Tried converting to lowercase before comparing too. As a test I tried it with just a single condition, and both conditions individually work.
In the end I changed the code and used a Select Case. Not quite as short on the code, but the same end result and possibly more elegant.
For Each objSubfolder in colSubfolders
Select Case LCase(objSubfolder.Name)
Case "system volume information", "$recycle.bin"
Case Else
Code to check goes here
End Select
Just another really annoying 10 minutes trying to work out something that should just work!
The logic to exclude both those folders before any code is executed should be AND. In algorithm speak you want:
if
(current file is NOT "System Volume Information")
AND
(current file is NOT "$RECYCLE.BIN")
{
deal with the current file / folder
}
Use a spreadsheet with formulae matching your if statement to validate the logic. For example, column A has the sample folder names, column B the formula, which in Excel speak is =if(or(a1″System Volume Information”,a1″$RECYCLE.BIN”),True,False). Column C has the same formula, but uses AND instead of the OR. Compare the column values.
The OR logic *WILL* result in *EVERY* folder resulting in a result of TRUE as either of those folders will always make the other test TRUE.
Hope this helps,
Keith
Thanks Keith,
Turnsd out my copy typing is not that good – in my original script that I used I had put the AND in the correct place. Thanks for noticing the correction on the site though. I have now updated the code.
Cheers
Craig.
Thanks Craig – I will look for it.
The ‘owner’ of the folder but stumped me for quite a while. I found the answer by looking through the Event Viewer on one of our clients.
I will dig out the script and post the code. Not sure it is all quite as elegant as it could be, but it works.
Interesing article – I have been fighting a folder redirection issue and I may have just found the answer in your blog about “which only works when the user is the owner of their folder”.
http://serverfault.com/questions/112154/windows-7-folder-redirection-gpo
I would like to see your folder check code you mentioned above, as if that is the case above, we will need a script to make all of the users “Owners” of their folders.
I really liked reading your post!. Quallity content. With such a valuable blog i believe you deserve to be ranking even higher in the search engines :). Check out the link in my name. That links to a tool that really helped me rank high in google. This way even more people can enjoy your posts and nothing beats a big audiance ;)