Jump to content
Jewtus

UpDir for any path

Recommended Posts

Jewtus

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>

Share this post


Link to post
Share on other sites
Exit

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

  • Like 1

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
TheSaint

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.

  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites
BetaLeaf

Its called updir, so it can be safely assumed we are dealing with directories and not files ;)


False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting.

PortableApps.com App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites
TheSaint

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

  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

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

×