daslick Posted October 9, 2006 Share Posted October 9, 2006 I have the full path of a file and I need its file name... how can I do this? Thanks Link to comment Share on other sites More sharing options...
cppman Posted October 9, 2006 Share Posted October 9, 2006 (edited) Func _GetFileName($sFullPath) $str = StringSPlit($sFullPath, "\") return $str[$str[0]] EndFunc ProcessClose(_GetFilename(@WindowsDir&"\explorer.exe")) Better example. Edited October 9, 2006 by CHRIS95219 Miva OS Project Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 9, 2006 Moderators Share Posted October 9, 2006 Func _GetFileName($sFullPath) $str = StringSPlit($sFullPath, "\") return $str[$str[0]] EndFunc ProcessClose(_GetFilename(@WindowsDir&"\explorer.exe")) Better example. 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 More sharing options...
Moderators SmOke_N Posted October 9, 2006 Moderators Share Posted October 9, 2006 $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 More sharing options...
daslick Posted October 9, 2006 Author Share Posted October 9, 2006 (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 October 9, 2006 by daslick Link to comment Share on other sites More sharing options...
daslick Posted October 9, 2006 Author Share Posted October 9, 2006 Ok, whatever - I just used someones code I understood. Thanks CHRIS95219. Pfff Larry Link to comment Share on other sites More sharing options...
Valik Posted October 9, 2006 Share Posted October 9, 2006 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 More sharing options...
/dev/null Posted October 9, 2006 Share Posted October 9, 2006 I have the full path of a file and I need its file name... how can I do this? Thanks.*\\(.*)CheersKurt __________________________________________________________(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 More sharing options...
Valik Posted October 9, 2006 Share Posted October 9, 2006 .*\\(.*)CheersKurt*Ahem*.*(?:\\|/)(.*)(Not totally sure how you can use the or operator so the non-capturing group may not be necessary.) Link to comment Share on other sites More sharing options...
/dev/null Posted October 9, 2006 Share Posted October 9, 2006 (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 October 9, 2006 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 More sharing options...
cppman Posted October 9, 2006 Share Posted October 9, 2006 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? Miva OS Project Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 9, 2006 Moderators Share Posted October 9, 2006 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 More sharing options...
cppman Posted October 9, 2006 Share Posted October 9, 2006 ah i see. thx. Miva OS Project Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now