Sign in to follow this  
Followers 0
Squirrely1

_StringExtractDirectory

16 posts in this topic

#1 ·  Posted (edited)

I haven't gotten many complaints about these UDF's. These func's are designed to be rigorous about not failing and not returning anything undesirable. Please tell me if you find any errors in this script.

_StringExtractDirectory() returns the folderpath when it is passed a filepath.

_StringExtractFilename() returns a file's name minus its path when it is passed a filepath.

_StringPathCapable() makes a passed string to be a valid Filepath or Folderpath name (beta req'd)

That last func will be helpful for when a user types-in a path.

Original post

These includes files have been updated to fix a glitch wherein a trailing backslash specified by a switch didn't work right if the folder was a driveletter followed only by a colon. ( _StringExtractDirectory lines 232 -256 ) :P

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites



Heads up. The includes files in the first post have been updated to fix a glitch wherein a trailing backslash specified by a switch didn't work right if the folder was a driveletter followed only by a colon. ( _StringExtractDirectory lines 232 -256 )


Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Great, just what I was looking for.

Thanks!


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Does this work any better than _PathSplit (File.au3 in UDFs)?

Saves a couple of lines and a few variables, plus looking through help (or testing) to find out if each part has a trailing '\' etc.

A simple one liner is easier to follow in the code as well. At least to me.


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

I agree with Stumpii. The downside of these UDF's is that they haven't been tested very thoroughly, and they are bigger than they might need to be because of their rigor, but <File.au3> is pretty big. Some people might like the rigorousness of _StringPathCapable( ) for instance, to not return anything invalid. :)


Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It baffles me how people can re-invent the wheel from scratch but they can't think of the simple thing like writing a wrapper around an existing function:

Func _FileGetPath($sFile)
    Local $sDrive, $sDir, $sName, $sExt
    _PathSplit($sFile, $sDrive, $sDir, $sName, $sExt)
    Return _PathMake($sDrive, $sDir, "", "")
EndFunc; _FileGetPath()

You want a simple function? Check.

You want a proven back-end that is bug-free? Check.

You get the idea.

Edit: Typo (Fixed).

Edited by Valik

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It baffles me how people can re-invent the wheel from scratch but they can't think of the simple thing like writing a wrapper around an existing function:

Func _FileGetPath($sFile)
    Local $sDrive, $sDir, $sName, $sExt
    _PathSplit($sFile, $sDrive, $sDir, $sName, $sExt)
    Return _PathMake($sDrive, $sDir, "", "")
EndFunc; _FileGetPath()

You want a simple function? Check.

You want a proven back-end that is bug-free? Check.

You get the idea.

Edit: Typo (Fixed).

It is sad when I find young upstarts with experience no greater than that is possessed by black-and-white or other, eight-year-old Hollywood starlets from the 1950's, disrespecting one of the forefathers of our chosen programming language, as might occur when I find someone not recognizing that . . .

1. The function Valik wrote does not work, as is.

2. That (more importantly), Valik the great did not intend to hand-over as though on a silver platter, to every young upstart AutoIt programmer-spammer on the planet, the eternal keys to wealth, health, and path functionality, and . . .

3. That someone of this mark should complain against Valik with the result that the fame of a new and newly-incisive Valik quote, his subsequent reply, might begin to spread far and wide across planet Arsnone. :)

footnote A: Valik's approach probably is more efficient than _StringExtractDirectory( ), but doesn't have my happy switch, for you young upstart newbies that don't want to be troubled about something as basic as getting a path.

footnote B: (RE: "2. . . ." above) Read "this function only describes an approach to building such a function for yourself" in Valik's above "You get the idea".

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

1. The function Valik wrote here, does not work as is.

Care to elaborate? Are you referring to the fact that I did not "#include <File.au3>" in that snippet? Otherwise... care to elaborate?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@Valik: There, I got your attention. I didn't really intend that you be bothered about such a little thing as the above, by such a little person as pictured to the left. I really wanted instead to lay down a stamp of authority regarding an issue raised over in that AutoIt Chat forum, active topic 'Valik Quotes'. The conversation there though, degraded into arguments about Hitler as well as deviant sex, so it looks as though that thread will die. That said, I hereby confer authority upon those in my signature below, the mark "suitable and sufficient for publication, Favorite Valik Quotes, Redacted Authorized Version (RAV), The Second Edition" (suitable for ages eight and up) on this, the Ninth Day in the Month of September, in the Year of Our Lord and Saviour, Twenty-Hundreds and Six. Amen and Amen. :)

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

:P ...and how does this explain whats wrong with the UDF or Snippet ?

My sincere appologies JdeB and Valik. The documentation for _PathSplit( ) is so poor, and I've never used the function. I couldn't understand before, just by looking at Valik's function, just where these variables were given a value to pass: $sDrive, $sDir, $sName, and $sExt. Note, I have been an amateur programmer for some years and have been using AutoIt for about 18 months. But you are correct. Now that I've tried it, the following code does indeed work. :)

#include <File.au3>
$a = _FileGetPath("C:\Squirrely1.txt" )
MsgBox(64, "My Path", $a )

;Valik's func:
Func _FileGetPath($sFile)
    Local $sDrive, $sDir, $sName, $sExt
    _PathSplit($sFile, $sDrive, $sDir, $sName, $sExt)
    Return _PathMake($sDrive, $sDir, "", "")
EndFunc; _FileGetPath()

There should be someone working on better documentation for those beta functions. But I could have heeded verses 1 thru 4 below.

I guess I am still too much of a stranger to the use of 'ByRef' which is used in File.au3.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

My sincere appologies JdeB and Valik. The documentation for _PathSplit( ) is so poor, and I've never used the function.

Poor documentation really means in this case that you didn't understand some basics and thus don't understand the explanation given in the Helpfile. The example looks clear enough to me, when run it demonstrates exactly what it does.....

I guess I am still too much of a stranger to the use of 'ByRef' which is used in File.au3.

A parameter without Byref is passed to the Func () one way.

A parameter with ByRef, the pointer is passed meaning that the Func () is using the same variable and when it updates it, its updated in its source.

Here's a little demo:

$a = 1
Demo_1($a)
MsgBox(0,"Value is NOT passed back from Func",$a)
;
$a = 1
Demo_2($a)
MsgBox(0,"Value is passed back from Func",$a)
;
Func Demo_1($x)
    $x = 2
EndFunc
;
Func Demo_2(ByRef $x)
    $x = 2
EndFunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Thanks for the demo, JdeB. It makes the use of ByRef completely clear.

Now, as for Valik's function:

Func _FileGetPath($sFile)
    Local $sDrive, $sDir, $sName, $sExt
    _PathSplit($sFile, $sDrive, $sDir, $sName, $sExt)
    Return _PathMake($sDrive, $sDir, "", "")
EndFunc; _FileGetPath()

If I understand what Valik does here then, he initializes $sDrive and $sDir locally, then passes

them with their initial null content to _PathSplit() which accepts four variables

'in the ByRef manner'; $sDrive and $sDir thereby get useful content assigned to them. And disregarding

whatever _PathSplit() returns, Valik makes the return value from his function to be

what is returned by _PathMake() when it is passed the same local variables $sDrive and $sDir.

I could unthinkingly jump to the conclusion from this whole discussion that the prescription below in verse 6, should be applied to mineself? :)

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Squirrely1, please use the default color for your signature. Using colors other than default means there's a really good chance people can't read it. I for one can't make much out without needlessly straining my eyes. Purple clashes with gray pretty hard.

I think you begin to understand ByRef now.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

$Compliance = $Requested

I am using mostly the default colors now, oh vaunted one.

For your own copy of the newly-revision rules of canon law, see the below link.

$SubstantialCompliance = ObjCreate("Squirrely1.Jedi").Link($Now.Applied)

Edited by Squirrely1

Das Häschen benutzt Radar

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