Wombat Posted September 30, 2013 Share Posted September 30, 2013 (edited) Ok, so a quick question: If I have a filepath: F:FolderFile.lst OR F:FolderFolderFile.lst and I wanted to extract information from it as such: Array #1 = File.lst & Array #2 = Folder(the folder name directly behind the backslash infront of the file) How would i do this? I'm trying to wrap my head around StrinRegExReplace but its a beast above my current level... EDIT: Possibly a better explanation of what i need to extract is: F:FolderFile.lst OR F:FolderFolderFile.lst $Foldername = █ $Filename = █ Edited September 30, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Solution DW1 Posted September 30, 2013 Solution Share Posted September 30, 2013 I'm no regex Guru, but this works for me $sString = "F:\Folder1\Folder2\File.lst" $aFoldername = StringRegExp($sString, '.*\\(.*)\\', 3) $aFilename = StringRegExp($sString, '.*\\(.*)', 3) Wombat 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 30, 2013 Share Posted September 30, 2013 (edited) Necessary Conditions The Path should end up with a file-name having an extension. There should be no "." periods in folder-name. #include <Array.au3> $sPath = "F:\Folder\File.xx" $aRet = StringRegExp($sPath, "([^\\]*)\\([^\\.]*\..*$)", 3) _ArrayDisplay($aRet) There is an _PathSplit() func included with Autoit, it should help you. Simultaneously if you search the forum you would get plently examples involved with _PathSplit and regex. Regards Edited September 30, 2013 by PhoenixXL Wombat 1 My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Wombat Posted September 30, 2013 Author Share Posted September 30, 2013 Necessary Conditions The Path should end up with a file-name having an extension. There should be no "." periods in folder-name. #include <Array.au3> $sPath = "F:\Folder\File.xx" $aRet = StringRegExp($sPath, "([^\\]*)\\([^\\.]*\..*$)", 3) _ArrayDisplay($aRet) There is an _PathSplit() func included with Autoit, it should help you. Simultaneously if you search the forum you would get plently examples involved with _PathSplit and regex. Regards didn't even think along the lines of PathSplit()... I was stuck in Array/String though process Thanks PhoenixXL! and thank you danwilli for the answer to the thread, I hope this helps others on the forum Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
mikell Posted September 30, 2013 Share Posted September 30, 2013 The same as Phoenix' one but without conditions #include <Array.au3> $sPath = "F:\Fol.der1\Fol.der2\File" $aRet = StringRegExp($sPath, "([^\\]*)\\([^\\]+?$)", 3) _ArrayDisplay($aRet) Wombat 1 Link to comment Share on other sites More sharing options...
Wombat Posted September 30, 2013 Author Share Posted September 30, 2013 (edited) The same as Phoenix' one but without conditions #include <Array.au3> $sPath = "F:\Fol.der1\Fol.der2\File" $aRet = StringRegExp($sPath, "([^\\]*)\\([^\\]+?$)", 3) _ArrayDisplay($aRet) Excellent! I really wish I understood StringRegExp... it hurts meh brain Edited September 30, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
mikell Posted September 30, 2013 Share Posted September 30, 2013 Then take care of your brain and use the traditional way #include <Array.au3> $sPath = "F:\Fol.der2\File" $split = StringSplit($sPath, "\") $n = $split[0] $split[0] = $split[$n] $split[1] = $split[$n-1] Redim $split[2] _ArrayDisplay($split) Link to comment Share on other sites More sharing options...
Wombat Posted September 30, 2013 Author Share Posted September 30, 2013 (edited) Then take care of your brain and use the traditional way #include <Array.au3> $sPath = "F:\Fol.der2\File" $split = StringSplit($sPath, "\") $n = $split[0] $split[0] = $split[$n] $split[1] = $split[$n-1] Redim $split[2] _ArrayDisplay($split) Wow, so many options... its like a candy store! Edited September 30, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... 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