Link to home
Start Free TrialLog in
Avatar of kulisncc
kulisncc

asked on

Need help with this simple vbs script

i want to be able to delete a folder located in %userprofile% and this is not working. Here is the code:
Dim FSO, Folder

set FSO=CreateObject("Scripting.FileSystemObject")

user=oShell.ExpandEnvironmentStrings("%UserName%")

Folder=user &"\StratECUpgrd"

FSO.DeleteFolder(Folder)

Open in new window

Avatar of yobri
yobri
Flag of United States of America image

The user variable is not declared.

Dim FSO, Folder, user
Avatar of kulisncc
kulisncc

ASKER

dammit!! I knew it was something miniscule. i will try that. thanks
didnt work, the directory is still there in the user's profile.
Sorry, I got called away, now back at keyboard.

Try this script on for size...

Dim WshSysEnv, WshShell, strUser

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oShell = CreateObject("Wscript.Shell") 

strUser = oShell.ExpandEnvironmentStrings("%USERPROFILE%")

objFSO.DeleteFolder strUser & "\StratECUpgrd"

Open in new window

One more time.... >_<

Dim objFSO, oShell, strUser

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oShell = CreateObject("Wscript.Shell") 

strUser = oShell.ExpandEnvironmentStrings("%USERPROFILE%")

objFSO.DeleteFolder strUser & "\test"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of yobri
yobri
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well something is amiss because it is still not deleting this directory
Use my latest code (IS: 35758266), if you hadn't. The next to latest had a target directory of 'test' as I wanted to make sure all worked on my end before I posted here, and of course, I forgot to update it to 'StratECUpgrd' instead.

Which OS are you working on by the way? I ran successful tests of this with XP and Win7. Any errors that you are encountering?
yeah i changed the Dim FSO and delcared the other variables and it ran great. You are the man brotha - kisses.

Just kidding about the kisses dude - LOL
Glad it all worked out there. Sorry for the constant code revisions... severe Friday brain here at work... -___-