Jump to content

Trailing backslash in @workingdir


Recommended Posts

I was wondering if anyone knows a simple what to get rid of the trailing "\" in @working dir when it is in the root of the drive....

If i use @workingdir in the root of the drive (like F:, no folder) its value would come up as "F:\"...but if its in a dir (like F:\dir) it would come up as "F:\dir"

is their a way to either make the traing backslash on the drive to go away or to always put it?

right now i am doing this

If IniRead($settings, "Script_Settings", "Working_Dir", "") = "" Then

IniWrite($settings, "Script_Settings", "Working_Dir", @WorkingDir)

EndIf

Dim $workingdir = IniRead($settings, "Script_Settings", "Working_DIR", "")

If FileExists($workingdir & @ScriptName) = 0 Then

Dim $workingdir = IniRead($settings, "Script_Settings", "Working_DIR", "") & "\"

Endif

usually my program is on a cd root...but when i work on it its not in a root folder...and untill i did the above change...i had to add the trailing backslash when i tested it on my computer

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

maby you should have posted in the bugreport section :whistle:

<{POST_SNAPBACK}>

well it may be a bug....but i did know if their may have been an option...and i was hoping someone had a solution...i'll post it in the bug section 2 Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

If you put this in the start of the program then you should be fine....

$Working_dir=@WorkingDir
If StringLen($Working_Dir)=3 Then  ;<--To make sure you are on a root dir
$Working_Dir=StringTrimRight($Working_Dir,1)
EndIf

Then you have to always use $Working_Dir instead of @WorkingDir....

C ya

Link to comment
Share on other sites

If you put this in the start of the program then you should be fine....

$Working_dir=@WorkingDir
If StringLen($Working_Dir)=3 Then  ;<--To make sure you are on a root dir
$Working_Dir=StringTrimRight($Working_Dir,1)
EndIf

Then you have to always use $Working_Dir instead of @WorkingDir....

C ya

<{POST_SNAPBACK}>

I like this solution...i am already using $workingdir as the variable with my current solution....and also...i havent even looked at the string coding....because of this i will have to check it out

But i think i will use your suggestion

I am changing it a little because the $workingdir variable is used in my script to reference were the install files are....but i also want this a changeable variable...so the dir can be specified in the ini...so basically i end up with the same about of code....but this is definatly a better way to do it

If IniRead($settings, "Script_Settings", "Working_Dir", "") = "" Then

IniWrite($settings, "Script_Settings", "Working_Dir", @WorkingDir)

EndIf

$workingdir= IniRead($settings, "Script_Settings", "Working_DIR", "")

If StringLen($workingdir)=3 Then

$workingdir=StringTrimRight($workingdir,1)

EndIf

Dim $workingdir = $workingdir & "\"

what if ya use SetWorkingDir :whistle:

<{POST_SNAPBACK}>

I was under the impression marcos wern't changable Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

what about this

$workingdir=@WorkingDir

If StringLen($workingdir)<>3 Then

     $workingdir=$workingdir & "\"

EndIf

or in my case.... if this works i can have it like this

If IniRead($settings, "Script_Settings", "Working_Dir", "") = "" Then

    IniWrite($settings, "Script_Settings", "Working_Dir", @WorkingDir)

EndIf

Dim $workingdir = IniRead($settings, "Script_Settings", "Working_Dir", "")

If StringLen($workingdir)<>3 Then

    $workingdir = $workingdir & "\"

EndIf

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Just FYI, a path such as "C:\" does NOT have a trailing back slash. That backslash IS the path, because for example "C:WINDOWS" and "C:\WINDOWS" can be 2 completely different folders. A path such as "C:\WINDOWS\" has a trailing backslash.

It is not a bug to return "C:\" as a path - if you were to return "C:" as a path, that WOULD be a bug, since "C:" isn't a path, it's a drive.

I assume you want to use a path where you know weather or not it has a backslash at the end so that you can add a file and/or relative path to it? I have a function to do this, you might be interested in:

;===============================================================================
;
; Function Name:    _FileJoinPath
; Description:    Takes "C:\Path" and "FileName.Ext" and returns "C:\Path\FileName.Ext"
; Parameter(s):
; Requirement(s):   _FileParsePath
; Return Value(s):  string
; Author(s):        Mike Ratzlaff <mike@ratzlaff.org>
;
;===============================================================================
;
Func _FileJoinPath($FileName1, $FileName2)
    Dim $PP1 = _FileParsePath($FileName1)
    Dim $PP2 = _FileParsePath($FileName2)
    If $PP2[0] <> '' Then Return $FileName2
    If StringLeft($PP2[1], 1) = '\' Then Return $PP1[0] & $PP2[1] & $PP2[2] & $PP2[3]
    If StringRight($FileName1, 1) <> '\' Then
        Return $FileName1 & '\' & $FileName2
    Else
        Return $FileName1 & $FileName2
    EndIf
EndFunc  ;==>_FileJoinPath

;===============================================================================
;
; Function Name:    _FileParsePath
; Description:    Takes a full path such as "C:\Path\File.Ext" and returns an array such as "C:","\Path\","File",".Ext"
; Parameter(s):
; Requirement(s):
; Return Value(s):  A 4-element Array.  See Description
; Author(s):        Mike Ratzlaff <mike@ratzlaff.org>
;
;===============================================================================
;
Func _FileParsePath($FileName)
    Dim $Return[4];Drive, Path, Name, Extension
    Dim $Len
    If StringMid($FileName, 2, 1) = ":" Then
        $Return[0] = StringLeft($FileName, 2)
        $FileName = StringRight($FileName, StringLen($FileName) - 2)
    Else
        $Return[0] = ''
    EndIf
    $Len = StringInStr($FileName, "\", 0, -1)
    $Return[1] = StringLeft($FileName, $Len)
    $FileName = StringRight($FileName, StringLen($FileName) - $Len)
    $Len = StringInStr($FileName, ".", 0, -1)
    $Return[2] = StringLeft($FileName, $Len - 1)
    $FileName = StringRight($FileName, StringLen($FileName) - $Len + 1)
    $Return[3] = $FileName
    Return $Return
EndFunc  ;==>_FileParsePath
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...