Sign in to follow this  
Followers 0
Mick

Useful Script

6 posts in this topic

I couldn't find this anywhere else, so I wrote a script to separate a pathname and filename from a full path/filename.

; Splits the filepath into DIR or FILENAME, pass full filepath as VAR1, required part as VAR2
; eg Pass (C:\Windows\System32\notepad.exe, 0) to return C:\Windows\System32
; eg Pass (C:\Windows\System32\notepad.exe, 1) to return notepad.exe
Func _SplitFilePath($VAR1, $VAR2)
    $PathBits = StringSplit ($VAR1, "\")
    $SplitFileName = $PathBits[$PathBits[0]]
    If $VAR2 = 0 Then
        $ReturnValue = StringTrimRight ($VAR1, StringLen ($SplitFileName) + 1)
    Else
        $ReturnValue = $SplitFileName
    EndIf
    Return $ReturnValue
EndFunc

If this already exists as a function can someone point it out please? Otherwise, could it be added to next BETA as it's quite useful (to me at least).

Thanks.

Share this post


Link to post
Share on other sites



Nice

another solution :)

$filepath = "c:\Windows\notepad.exe"
$file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))
$Path = StringLeft($filepath,StringInStr($filepath,"\",0,-1)-1)
MSGBOX(0,"Result",$Path &" | "&$file)

Share this post


Link to post
Share on other sites

HI,

right from help.

#include <file.au3>
#include <array.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$TestPath = _PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt)
_ArrayDisplay($TestPath,"Demo _PathSplit()")

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Like th.meger said, _PathSplit is the way to go. However, here is my crack at doing it in one less line than Micha:

$filepath = "c:\Windows\notepad.exe"
$a_result = stringregexp($filepath,'([a-zA-Z]:\\[^/:*?"<>|\r\n]*[\\])([^/:*?"<>|\r\n]*\.[a-zA-Z0-9]{3})',1)
If IsArray($a_result) Then MSGBOX(0,"Result","Path: "&$a_result[0] &@CRLF&"File: "&$a_result[1])

:)


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Like th.meger said, _PathSplit is the way to go. However, here is my crack at doing it in one less line than Micha:

$filepath = "c:\Windows\notepad.exe"
$a_result = stringregexp($filepath,'([a-zA-Z]:\\[^/:*?"<>|\r\n]*[\\])([^/:*?"<>|\r\n]*\.[a-zA-Z0-9]{3})',1)
If IsArray($a_result) Then MSGBOX(0,"Result","Path: "&$a_result[0] &@CRLF&"File: "&$a_result[1])

:)

HI,

NICE, but you have to change a little bit, otherwise it only works if the extension is 3 chars long. What about e.g config.properties files :(

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Try this:

Func _Extenstion($filename)
$string=StringSplit($filename,".")
Return $string[$string[0]]
EndFunc

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]

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  
Followers 0