Jump to content
Sign in to follow this  

@scriptdir() and (not) trailing backslash

Recommended Posts


The Macro Reference tells for the macro @ScriptDir:

@ScriptDir: Directory containing the running script. (Result does not contain a trailing backslash) :party:

I just recognized, that @ScriptDir DOES :) return a trailing backslash when the script is runned from a drive's root directory.

So when I add other relative path information to the return string of @ScriptDir(), I have to check for double Backslashes like this, as the script might be runned from the root folder of update CDs:

; some script doing several updates from CDROM, maybe the stript is started from<cdrom>:\
$SrcDir=StringReplace(@ScriptDir & $RelPath,"\\","\")

Of course I'm aware that a "<driveletter>:" is just the drive's current directory, which might be a path not pointing to the drive's root folder. But IMHO either the trailing backslash should be added for both, the ROOT folder and all subfolders, or for none of both... :)

Minor bug?

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post

Link to post
Share on other sites

@ScriptDir says

Directory containing the running script.

A drive would not be a directory. I have run into this issue with other programming languages as well. If your script and/or application is being run from a drive and you look at the @ScriptDir, or Application.ExecutablePath for some .NET applications, it will always return the Drive:\

This is what I do to check for this in AutoIT

Func NeedSlash($sPath, $sDelim="\")
    If StringRight($sPath, 1) <> $sDelim Then
        $sPath &= $sDelim

Just call the above function and if it NEEDS a \ it will add it, if it does not need it it will just return what was passed to it.

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...