Jump to content

UpDir for any path


Jewtus
 Share

Recommended Posts

Simple command but I couldn't find it when I went looking on the boards. I got the idea while looking for a way to get scriptdir's parent folder (Took the command from HERE)

Func GetParent($sDir,$nUpDirs=0)
    local $sUpdir
    For $z=0 to $nUpDirs
        $sUpdir=$sUpdir&"..\"
    Next
    $Parent_DIR = _PathFull($sDir&$sUpdir)
    Return $Parent_DIR
EndFunc

Give it a path and the number of folders up you want to go and it returns the path. Requires #include <File.au3>

Link to comment
Share on other sites

Or

$sDir = @AppDataDir



$sMsg = $sDir & @LF

$sMsg &= _GetParentDir($sDir) & @LF
$sMsg &= _GetParentDir($sDir, 2) & @LF

MsgBox(262144, Default, $sMsg, 0)

Func _GetParentDir($sDir, $nUpDirs = 1)
    Return StringLeft($sDir, StringInStr($sDir, "\", 0, $nUpDirs * -1) - 1)
EndFunc   ;==>_GetParentDir

now, it's up to the RegEx freaks to show a RegEx solution. :D

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

You should have error checking.

You should also use something like StringSplit, to tell how many up folders there are, and also cater for the drive letter.

_PathSplit is probably the better way to go too, and determining whether the original path is to a folder or file.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I suggest you think about that. ;)

Directories or folders, also have Up Directories, so the path given could be either a file or folder path. ;);)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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