Sign in to follow this  
Followers 0
daslick

path vs. filename

13 posts in this topic

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

Thanks

Share this post


Link to post
Share on other sites



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()?

[center]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.[/center]

Share this post


Link to post
Share on other sites

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Ok, whatever - I just used someones code I understood. Thanks CHRIS95219. Pfff Larry

Share this post


Link to post
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.

Share this post


Link to post
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 *

Share this post


Link to post
Share on other sites

.*\\(.*)

Cheers

Kurt

*Ahem*

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

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?

[center]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.[/center]

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