autog Posted November 13, 2011 Share Posted November 13, 2011 Hi, I need to replace full paths from a list of path-files, like: D:\folder\file with spaces.ext E:\folder\subfolder\another file.ext \\networkdrive\folder\yet another file.ext to become, e.g. Z:\MyFolder\file with spaces.ext Z:\MyFolder\another file.ext Z:\MyFolder\yet another file.ext Totally non-standard list, mapped or network drives, I have to rely on string manipulation. I know a bit of cmd it can easily spot paths (%~pa - expands %a to a path only), but cmd looks "disabled" when it comes to manipulating/replacing strings. As for an autoit algorithm, I was thinking: - search extension, get its position - search backwards for backslash (is it possible?, how?) and get its position on line $posslash - [if string exists] replace string between $pos1=>$posslash with "Z:\MyFolder" I would very much appreciate your help with some hints/example. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2011 Moderators Share Posted November 13, 2011 autog, I wiuld extract the filename plus extension and then add the new path: Global $aFiles[3] = ["D:folderfile with spaces.ext", " E:foldersubfolderanother file.ext", "networkdrivefolderyet another file.ext"] $sBase_Path = "Z:MyFolder" For $i = 0 To 2 ; Extract filename with extension $sFileName = StringRegExpReplace($aFiles[$i], "^.*", "") ; Add to base path ConsoleWrite("New path = " & $sBase_Path & $sFileName & @CRLF) Next All clear? 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...
autog Posted November 13, 2011 Author Share Posted November 13, 2011 That was fast , thanks for "extracting" idea, but I do need to replace because I need final list to keep the same line sequence. My mistake, didn't explain completely, original list contains multiple lines I don't want to touch: line01 random content line02 random content D:folderfile with spaces.ext line04 random content line05 random content line06 random content line07 random content E:foldersubfolderanother file.ext line09 random content line10 random content networkdrivefolderyet another file.ext line12 random content line13 random content etc Result needed is all lines intact, except paths changed to mine. Hmm.. maybe to read each line, write it to new list and if found extension, do your extraction/add solution? I'd find easier to grab paths in a list and loop-replace them until none found, but no idea how to do it. In the meantime I'll also work on Melba23's idea. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2011 Moderators Share Posted November 13, 2011 autog, My mistake, didn't explain completelyAlways helps! So test the line before you alter it: Global $aLines[13] = ["line01 random content", _ " line02 random content", _ " D:folderfile with spaces.ext", _ " line04 random content", _ " line05 random content", _ " line06 random content", _ " line07 random content", _ " E:foldersubfolderanother file.ext", _ " line09 random content", _ " line10 random content", _ " networkdrivefolderyet another file.ext", _ " line12 random content", _ " line13 random content"] $sBase_Path = "Z:MyFolder" For $i = 0 To UBound($aLines) - 1 If StringRegExp($aLines[$i], "(?i)((w:|).+.w{3})") Then ; See if it holds a path ; And change it if it does $sFileName = StringRegExpReplace($aLines[$i], "^.*", "") ConsoleWrite($sBase_Path & $sFileName & @CRLF) Else ; Or leave it alone if not ConsoleWrite($aLines[$i] & @CRLF) EndIf Next Any better? M23 P.S. Welcome to the AutoIt forum, by the way! 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...
autog Posted November 13, 2011 Author Share Posted November 13, 2011 Uff, it looks great! Doing the job... What a welcome! The only "worry" I have is I'll probably need some loooong time to digest and understand the ugly stringregexp and your beautiful coding . Thank you so much! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2011 Moderators Share Posted November 13, 2011 (edited) autog,SRE explanations: SRE: (?i) - Case insensitive ((w:|).+.w{3})") - This is what we look for - made up of (w:|) - Either a letter followed by : or (separated by a "|") a || .+ - At least one character followed by .w{3} - a . and 3 letters SRER: .* - Look for any number of characters followed by a backslash "" - Remove those charactersI leant a lot about SREs from this site and I still use it lot. M23Edit: Wrong explanation. Edited November 13, 2011 by Melba23 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...
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