?
Solved

Need help modifying this VBS code

Posted on 2011-10-24
5
Medium Priority
?
277 Views
Last Modified: 2012-05-12
I am using the below code to check to see if a specific  folder exists on a users share.  I need to change it so that it first determines if the user is mapping to an "M" drive.  If not it needs to see if they map to a "U" drive and if so, the folder should be created there.  Some users will map to a M:\ for user files and some of our new users will map to a U:\ for user files- so I need this to work for both, if possible.  Thanks!




Set fs = CreateObject("Scripting.FileSystemObject")

AppFolder = "M:\Apps"

If fs.FolderExists(AppFolder) = False then
      fs.CreateFolder AppFolder

End If
0
Comment
Question by:snyperj
  • 2
  • 2
5 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 37018831
You should be able to use the fso.DriveExists(drive) function, maybe something like this:

Set fs = CreateObject("Scripting.FileSystemObject")

If fs.DriveExists("M:") Then
    AppFolder = "M:\Apps"
Else
    AppFolder = "U:\Apps"
End If

If fs.FolderExists(AppFolder) = False then
    fs.CreateFolder AppFolder
End If

Open in new window

~bp
0
 
LVL 4

Assisted Solution

by:CharlWiehahn
CharlWiehahn earned 1000 total points
ID: 37018838
hi snyperj,

Here is a small variation to your existing code.
Set fs = CreateObject("Scripting.FileSystemObject")

If fs.FolderExists("u:\") then
	If fs.FolderExists(u:\Apps) = False then
		fs.CreateFolder "u:\Apps"
	End If
Elseif  fs.FolderExists("m:\") then
	If fs.FolderExists(m:\Apps) = False then
		fs.CreateFolder "m:\Apps"
	End If
End If

Open in new window

0
 

Author Comment

by:snyperj
ID: 37019333
As a test I tried both variations as shown below.  Not sure what I did wrong, but in both case I received and error that included:

"Cannot use paranthesis when calling a sub"


In both cases it was the line with the MsgBox(...




1st test---------------
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FolderExists ("U:\") Then
     MsgBox("U drive exists!",0,"")
Else
    MsgBox("U drive DOES NOT exist!",0,"")
End If


2nd test-----------------
Set fs = CreateObject("Scripting.FileSystemObject")

If fs.DriveExists("U:") Then
     MsgBox("U drive exists!",0,"")
Else
    MsgBox("U drive DOES NOT exist!",0,"")
End If

Open in new window

0
 

Author Closing Comment

by:snyperj
ID: 37019981
worked it out.  I have uses for both variations of this- so thanks.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37020570
Welcome.

~bp
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question