Jump to content

Recommended Posts

I was messing around with strings today, everything worked fine until i tried to remove things from a string (got a bit complicated).

What i am trying to do is (example: "C:\downloads\test dir\file.jpg") to get the file name, in this case "file" to be seperated from the rest of the line. I can remove the last 4 letters, since its fairly easy with a line of code :P

$var = "C:\downloads\test dir\file.jpg"
$result = StringTrimRight($var, 4)

So now i have ""C:\downloads\test dir\file"

It got alot more complicated now and im not sure how to proceed to remove everything before the last "\". Tried using StringSplit and StringTrimRight, but never got the result i was looking for.

Thanks for any help on this.

"I'm paper, rock is fine, nerf scissors!!!"

Link to post
Share on other sites

Surprised nobody has brought up _PathSplit()

#include <file.au3>
#include <array.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$TestPath = _PathSplit("C:\downloads\test dir\file.jpg", $szDrive, $szDir, $szFName, $szExt)
_ArrayDisplay($TestPath,"Demo _PathSplit()")

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...