Jump to content

Get @ScriptDir folder name


goldenix
 Share

Recommended Posts

foldername / get foldername

Hi.

I found that there are no actual function for this in the help file & for to my suprise no one has ever asked about this before ( at least this what the search said) I found you can get folder names from the @ScriptDir, but no idea how to get the folder name where my script resides.

My code so far, Any Hints?........

EDIT:Problem Resolved:

Credit goes to Buey. Thank you Buey

$a = StringSplit(@ScriptDir,"\",0)
MsgBox(0,"",$a[$a[0]])

Explanation:

Example:

$a = StringSplit("Sun\Mon\Tue", "\",0)

msgBox(0,"",$a[1])

msgBox(0,"",$a[$a[0]])

StringSplit splits the text & "\" is where the split happens

$a[1] is the number of the string ;in this example--> Sun

$a[0] == index of last string in array ;in this example--> Tue

so to display the last number of the srting-->$a[last_number] we must put it like this:

$a[$a[0]] == $'display'_number_of_the_string[$Index_of_last_string_in_array]

Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Hi.

I found that there are no actual function ... you can get folder names from the @ScriptDir, but no idea how to get the folder name where my script resides.

Huh?? What?? What you talk'n about Willis? This is from the Help file:

@ScriptName : Filename of the running script.

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

@ScriptFullPath : Equivalent to @ScriptDir & "\" & @ScriptName

Link to comment
Share on other sites

Huh?? What?? What you talk'n about Willis? This is from the Help file:

@ScriptName : Filename of the running script.

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

@ScriptFullPath : Equivalent to @ScriptDir & "\" & @ScriptName

all this is no good, because it will display full path look at the example

Example: MsgBox(0,'',@ScriptDir) ---> @ScriptDir = C:/scriptfolder

What im looking for is: scriptfolder so it should be displayed around like this MsgBox(0,'','scriptfolder')

EDITED to make it more understandable!

Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

What im looking for is: scriptfolder so it should be displayed around like this MsgBox(0,'',scriptfolder)

I'm still confused playa... lets see if we can't help each other understand and get you hooked up with some code da ladies will love.

The word Folder is the same as Directory, hello?? If we agree and based on your example where you say ";lets assume that @ScriptDir = C:/scriptfolder" you what the message box text to read what? Type that out for use to see. And if you are running a script who's full path including filename is C:\scrptfolder\project100\version12\myscript.au3, then @ScriptDir should return "C:\scrptfolder\project100\version12" So like I said earlier, what you talk'n about Willis???

It really shouldn't be that hard to get on the same page and help someone :)

Edit: On second thought, if you take a look at StringLeft() or StringBetween() if you want the @ScriptDir without the prompt.

Edited by ssubirias3
Link to comment
Share on other sites

$a = StringSplit(@ScriptDir,"\")
MsgBox(0,"",$a[$a[0]])
Wery simple thank you but do you mind to explain for less smart people? this is how far I understand:

StringSplit splits the text & "\" is where the split happens

if you put MsgBox(0,"",$a[1]) it will display first split in this example-->"C:/scriptfolder" its C:, i see how you make it display the last split by putting MsgBox(0,"",$a[$a[0]]) but i dont understand this part hire: $a[$a[0]]

Can you break it down & explain please?

Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

StringSplit

Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.

so $a[0] is the number of strings

In @ScriptDir, the current folder is the last string returned by StringSplit

so, the string that you want is at the end of the array.

$a[0] == index of last string in array

$a[$a[0]] is the string at the end of the array

Link to comment
Share on other sites

Wery simple thank you but do you mind to explain for less smart people? this is how far I understand:

StringSplit splits the text & "\" is where the split happens

if you put MsgBox(0,"",$a[1]) it will display first split in this example-->"C:/scriptfolder" its C:, i see how you make it display the last split by putting MsgBox(0,"",$a[$a[0]]) but i dont understand this part hire: $a[$a[0]]

Can you break it down & explain please?

When you split a String with StringSplit it creates an Array, which is what $a is.

The array contains all the split up parts, as you noticed by doing $a[1].

With an array created from StringSplit, the first element of the array, or in this case, $a[0], contains the total number of split parts.

Since you won't always now how many backslashes are in the scripts path- and therefore won't know how many split parts you have- you use $a[0] instead of 1 or 2, etc. So instead of $a[2], you use $a[$a[0]]

To make it a little easier to understand:

$a = StringSplit(@ScriptDir,"\")
$i = $a[0]
MsgBox(0,"",$a[$i]oÝ÷ Ù©Ýjëh×6StringSplit(@ScriptDir,"\")
MsgBox(0,"","There are " & $a[0] & " split parts to " & @ScriptDir & @CRLF & @CRLF & "Part # " & $a[0]  & " is " & $a[$a[0]])

EDIT Yeah, like what Buey said. I've got to stop starting my replies and then coming back to finish and post them without checking to see if somebody else beat me to it :)

EDIT2 Darn autoit code on editing gets all screwed up

Edited by ResNullius
Link to comment
Share on other sites

I edited my first post & re explaind it for less smart ppl like me....

Super, thank you both, I understand it now.

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

@Buey - sweet, good stuff understanding what goldenix was talking about. You nailed it on the first shot! You happen to know tomorrow's winning lotto numbers too?? :)

@goldenix - good deal brother, glad you got this working for you and more importantly, you better understand StringSplit(). Some of the other String functions would work for you too, depending on the circumstance of course. The most powerful, imo, String function is StringRegExp(). Oh man, datz some good butter if you can get your arms around dat beast.

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...