GEOSoft Posted August 11, 2011 Share Posted August 11, 2011 Well I certainly can see why Melba23 may be starting to get frustrated here.You are asking for too many things that just can't be done readily in a single expression using the examples you have provided.How are you getting this string that has to be parsed?Are these files only local or is there a possibility that they will be a UNC path?Do you want just Files or Files and Folders?Will any of the paths be relative?The first question is very important. If it's comming from a file then you may be able to pre-process the file before you start looking for the file paths. This is also possible with a simple string input but may or may not require more effort.I did manage to search one of the regex forums that I'm on and had no working hits on there either.I'll ask about it there if I have to but I think for now you should just answer the questions above. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Snoomi Posted August 11, 2011 Author Share Posted August 11, 2011 There are filenames that don't have an extension (like C:\Windows\System32\drivers\etc\hosts), so you can't rely on just regular expressions to do the job. A regular expression would either only look for files that have an extension, or also match folder names. To catch all files, you have to also collect directory names and filter them out later. dim $aFiles[7] = [6, "Hi, C:\WINDOWS\explorer.exe", "C:\WINDOWS\system32\shell32.dll", "C:\", "C:\WINDOWS\", "Hi, run C:\WINDOWS\svchost.exe", "hardcore sample C:\Windows\System32\drivers\etc\hosts"] ;_arraydisplay($aFiles) for $i = 1 to $aFiles[0] $path_and_file = stringregexp($aFiles[$i], "[a-z A-Z]\:\\.*", 1) if isarray($path_and_file) Then $filecheck = _isfile($path_and_file[0]) if $filecheck = 1 then msgbox(0, "is a file", $path_and_file[0]) Else msgbox(0, "is a directory", $path_and_file[0]) EndIf EndIf Next func _isfile($string) $attrib = FileGetAttrib($string) If StringInStr($attrib, "D") Then return(0); return 0 if directory return(1); otherwise return 1 EndFunc Thanks, but I already solved Link to comment Share on other sites More sharing options...
Snoomi Posted August 11, 2011 Author Share Posted August 11, 2011 Well I certainly can see why Melba23 may be starting to get frustrated here.You are asking for too many things that just can't be done readily in a single expression using the examples you have provided.How are you getting this string that has to be parsed?Are these files only local or is there a possibility that they will be a UNC path?Do you want just Files or Files and Folders?Will any of the paths be relative?The first question is very important. If it's comming from a file then you may be able to pre-process the file before you start looking for the file paths. This is also possible with a simple string input but may or may not require more effort.I did manage to search one of the regex forums that I'm on and had no working hits on there either.I'll ask about it there if I have to but I think for now you should just answer the questions above.Have solved Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 11, 2011 Moderators Share Posted August 11, 2011 Snoomi, Could you please explain how you solved it so that others might learn from your experience? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Snoomi Posted August 12, 2011 Author Share Posted August 12, 2011 Snoomi,Could you please explain how you solved it so that others might learn from your experience? M23Maybe I did not explain: I solved thanks to you lol Link to comment Share on other sites More sharing options...
Lazegalli Posted May 21, 2013 Share Posted May 21, 2013 I have a similar problem and I'm running out of ideas! Sadly Snoomi didn't explained how he solved his problem, so I ask again... How can I find all Pathes from this string: 'Path1="ServerNameTest File.txt" Path2=C:TestFolder Path3=D:testTestFileWithoutExtension' I try to realize a function, which really finds all Pathes in a given String, doesn't matter if it's a File/Folder or if there are some quotes around. Could anyone give me a helping hand? Link to comment Share on other sites More sharing options...
Malkey Posted May 22, 2013 Share Posted May 22, 2013 I have a similar problem and I'm running out of ideas! Sadly Snoomi didn't explained how he solved his problem, so I ask again... How can I find all Pathes from this string:'Path1="ServerNameTest File.txt" Path2=C:TestFolder Path3=D:testTestFileWithoutExtension' I try to realize a function, which really finds all Pathes in a given String, doesn't matter if it's a File/Folder or if there are some quotes around. Could anyone give me a helping hand?Try this.#include <Array.au3> Local $sTestStr = _ 'Path1="\\ServerName\Test File.txt" Path2=C:\TestFolder\ ' & _ 'Path3=D:\test\TestFileWithoutExtension Path4=''\\AnotherServerName\Test File2.txt''' $aRes = StringRegExp($sTestStr, "(?i)(?:Path\d+\=((?:""|')[^""']+(?:""|')|[^\h]+) ?)", 3) _ArrayDisplay($aRes, "With Quotation Marks") For $i = 0 To UBound($aRes) - 1 $aRes[$i] = StringRegExpReplace($aRes[$i], "([""'])", "") Next _ArrayDisplay($aRes, "Without Quotation Marks") ; Or, no arrays method. Local $sWithQuotes = StringRegExpReplace($sTestStr, "(?i)(?:Path\d+\=((?:""|')[^""']+(?:""|')|[^\h]+) ?)", "\1" & @CRLF) ; One path per line. ;Local $sWithQuotes = StringRegExpReplace($sTestStr, "(?i)(?:Path\d+\=((?:""|')[^""']+(?:""|')|[^\h]+) ?)", "\1 ") ; Space separation MsgBox(0, " With Quotation Marks ", $sWithQuotes, 4) Local $sWithOutQuotes = StringRegExpReplace($sWithQuotes, "([""'])", "") MsgBox(0, "** Without Quotation Marks **", $sWithOutQuotes, 5)Lazaegalli's and my test string only encloses a path containing spaces within quotes. Link to comment Share on other sites More sharing options...
Lazegalli Posted May 22, 2013 Share Posted May 22, 2013 Hey Malkey, many thanks for your help. This is exactly what I've tried to realize! Cheers Lazegalli 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