Re: FolderExists Help......... by Björn
Björn
Fri Apr 08 04:14:05 CDT 2005
"Momo" <louey-3@excite.com> wrote in message
news:1112944251.820902.191920@g14g2000cwa.googlegroups.com...
> I need to write a sniipet of code that will check all users profiles in
> Doc and Settings and check for a directory in
> \\Doc and setting\username\application data\
>
> I've managed to get the easy part of doing check on one directory but a
> bit lost on how to do it on the full doc and settings directroty using
> a Do While Loop....
>
> Dim fso, folder
>
>
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> AppData = "C:\Document and settings\"
>
> Do While ......
> If oFSO.FolderExists(AppData) Then
> wscript.echo "AppData Found"
> End If
>
> End....
>
>
> The thing is I'm not sure how to tell it to search through all the
> profiles....
>
> Anyone can provide some pointers please..............
>
Here's an example. I've added a lot of inline comments, but if there's
anything you don't understand, please let me know and I'll try to explain...
Const USERPROFILE = 40
Const APPDATA = 26
Dim objShell, objFSO, sUserProfile, objUserProfile, sAppDataFolder
Dim sAppData, objDocsAndSettings, objUser
Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get full path to current user profile
sUserProfile = objShell.Namespace(USERPROFILE).self.path
' Get user profile folder
Set objUserProfile = objFSO.GetFolder(sUserProfile)
' Get documents and settings folder (parent of profile folder)
Set objDocsAndSettings = objFSO.GetFolder(objUserProfile.ParentFolder)
' Get path to current user's application data folder
sAppDataFolder = objShell.Namespace(APPDATA).self.path
' Get name of application data folder
sAppData = objFSO.GetFolder(sAppDataFolder).Name
' Enumerate subfolders of documents and settings folder
For Each objUser In objDocsAndSettings.SubFolders
' Check if application data folder exists in user subfolder
If objFSO.FolderExists(objUser.Path & "\" & sAppData) Then
WScript.Echo "AppData found for user " & objUser.Name
Else
WScript.Echo "No AppData found for user " & objUser.Name
End If
Next
--
Björn Holmgren