Need help with this simple vbs script

kulisncc
kulisncc used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
The user variable is not declared.

Dim FSO, Folder, user

Author

Commented:
dammit!! I knew it was something miniscule. i will try that. thanks

Author

Commented:
didnt work, the directory is still there in the user's profile.
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Top Expert 2011

Commented:
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

Top Expert 2011

Commented:
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

Top Expert 2011
Commented:
OK, for real now... this is with your variables intact with included variable, etc. to make it all work:

Dim FSO, oShell, Folder, user

set FSO=CreateObject("Scripting.FileSystemObject")

Set oShell = CreateObject("Wscript.Shell") 

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

Folder=user &"\StratECUpgrd"

FSO.DeleteFolder(Folder)

Open in new window

Author

Commented:
well something is amiss because it is still not deleting this directory
Top Expert 2011

Commented:
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?

Author

Commented:
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
Top Expert 2011

Commented:
Glad it all worked out there. Sorry for the constant code revisions... severe Friday brain here at work... -___-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial