rrangel8
asked on
vbscript - if FolderExists question
Not sure what is going on with this script. I am trying to grab data from each users application data folder. If the file exists then echo. If you want to test then you can put a known folder.
Option Explicit
'Variables
Dim objShell,FSO
Dim strUserProfile,strAppData, objFile
Wscript.echo "working so far"
' Get the current users profile folder
Set objShell = CreateObject("WScript.Shel l")
strUserProfile=objShell.Ex pandEnviro nmentStrin gs("%USERP ROFILE%")
strAppData=objShell.Expand Environmen tStrings(" %APPDATA%" )
' Set reference to the file system
Set FSO = createobject("Scripting.Fi leSystemOb ject")
' Check if each folder exists.
If FSO.FolderExists(strUserPr ofile & strAppData) & "\Microsoft" = True Then
WScript.Echo "im here"
Else
WScript.Echo "not here"
End If
Option Explicit
'Variables
Dim objShell,FSO
Dim strUserProfile,strAppData,
Wscript.echo "working so far"
' Get the current users profile folder
Set objShell = CreateObject("WScript.Shel
strUserProfile=objShell.Ex
strAppData=objShell.Expand
' Set reference to the file system
Set FSO = createobject("Scripting.Fi
' Check if each folder exists.
If FSO.FolderExists(strUserPr
WScript.Echo "im here"
Else
WScript.Echo "not here"
End If
ASKER
this should work for all users with a profile on a machine.
Oh, then you need to approach this a little different.
Try this:
Try this:
'Create Objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get special folder paths
strAllUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
'Get Path of profile folder
strAllProfiles = objFSO.GetParentFolderName(strAllUserProfile)
Set objProfiles = objFSO.GetFolder(strAllProfiles)
'Exclude System Default Profiles
Set SkipProfilesArray = CreateObject("Scripting.Dictionary")
SkipProfilesArray.Add "Administrator", "Administrator"
SkipProfilesArray.Add "All Users", "All Users"
SkipProfilesArray.Add "Default User", "Default User"
SkipProfilesArray.Add "LocalService", "LocalService"
SkipProfilesArray.Add "NetworkService", "NetworkService"
'Check date of ntuser.dat in each profile folder and delete if criteria meet
For Each strUserProfile In objProfiles.SubFolders
If Not SkipProfilesArray.Exists(strUserProfile.Name) Then
If objFSO.FolderExists(strUserProfile & "\Desktop") Then
WScript.Echo "Folder Found for " & strUserProfile.Name
Else
WScript.Echo "Folder Missing or No Access for " & strUserProfile.Name
End If
End If
Next
WScript.Echo VbCrLf & "Script Finished"
ASKER
sorry guys...i was out of the office Friday. will test out today.
appreciate your help!
appreciate your help!
ASKER
RLANDQUIST,
thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.
thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.
ASKER
RLANDQUIST,
thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.
thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ahhh...i tried it earlier with "application data\microsoft" not like yours "\application data\microsoft"
Your the man.
So, let me expand on this if you will. Will this same logic work for FILES?
Your the man.
So, let me expand on this if you will. Will this same logic work for FILES?
Yes.
ASKER
th
%APPDATA% = C:\Users\YOURNAME\AppData
So you are saying you are looking for a folder named:
C:\Users\YOURNAMEC:\Users\
You just need
If FSO.FolderExists(strAppDat
To check variable locations open a command prompt and type set and press enter