Sign in to follow this  
Followers 0
Sn3akyP3t3

Get drive path of operating system

4 posts in this topic

I cannot find a means to identify the path of the OS drive without a degree of sloppiness and in all environments.

So far the only two means I know of are like so:

1.) Works so long as the home path resides on the same drive the OS does. Useless to me in my work environment.

$dir = @HomeDrive
MsgBox(0,"",$dir)

2.) Works for the most part, but really sloppy. Becomes a pain when having to use the path literally in comparisons or when treated as a string for StringCompare() functions since it needs to be sanitized of the workaround addition in the path before use.

$dir = @WindowsDir & '\..'
FileChangeDir($dir)
$dir = @WorkingDir
MsgBox(0,"",$dir)

Of course FileChangeDir() doesn't need to be used. It just produces quick viewable results to describe my problem.

Share this post


Link to post
Share on other sites



What if you grab the first three chars with StringLeft?

$sWindowsDir = StringLeft(@WindowsDir, 3)
MsgBox(0, "", $sWindowsDir)

Gives the same result as your script in half the lines :huh2:

Share this post


Link to post
Share on other sites

What if you grab the first three chars with StringLeft?

$sWindowsDir = StringLeft(@WindowsDir, 3)
MsgBox(0, "", $sWindowsDir)

Gives the same result as your script in half the lines :huh2:

Thanks! Leave it to me to over-analyze the simple stuff!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

EnvGet() is also handy to know if you want to use values from environmental variables.

$systemdrive = EnvGet('SystemDrive')
MsgBox(0, '$systemdrive', $systemdrive)

Edit:

fixed typo

Edited by MHz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0