Jump to content

path vs. filename


Recommended Posts

  • Moderators

Func _GetFileName($sFullPath)
    $str = StringSPlit($sFullPath, "\")
    return $str[$str[0]]
EndFunc
ProcessClose(_GetFilename(@WindowsDir&"\explorer.exe"))

Better example.

:lmao: That's not "always" going to work, anything wrong with _PathSplit()?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

$file = StringTrimLeft($YourPath,StringInStr($YourPath,"\",0,-1))

Lar.

Use a negative occurrence to search from the right side. The default value is 1 (finds first occurrence).

I'll admit I didn't know that! Thanks Lar.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I thought of that concept, looking for the last "\" but I had no idea how to do it. There's no way I could have written that either...

Thanks!!!!!

EDIT : I only have 1 variable - $addme which is the full path to a file, what is $YourPath?

Edited by daslick
Link to comment
Share on other sites

Did you also understand that it's probably the worst way to go about solving the problem? Larry's way isn't the best either although it's more efficient than the code you've chosen to use. Smoke's suggestion is far and away the best.

Link to comment
Share on other sites

I have the full path of a file and I need its file name... how can I do this?

Thanks

.*\\(.*)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

*Ahem*

.*(?:\\|/)(.*)

(Not totally sure how you can use the or operator so the non-capturing group may not be necessary.)

$path = "C:\test\test\abc123.txt"
$pattern = ".*\\(.*)"

$file = StringRegExp($path,$pattern,1)
msgbox(0,"","Path: " & $path & " File: " & $file[0])

BTW: I did not take "/" as a valid path delimiter as all the other solutions did not as well :-) But one can easily extend the pattern to this: ".*[\\|/](.*)"

EDIT: removed first sentence as I misunderstood the post.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Moderators

plz don't misconcept this post, im not trying to argue!

I don't understand how the code I provided would not work in a certain situation? Anyone Care to explain?

What happens when the path name uses forward slashes?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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