rootx Posted August 4, 2014 Share Posted August 4, 2014 (edited) $imgArray = _FileListToArrayRec("C:\images\", "*.jpg", 0, 0, 1, 2) ;_ArrayDisplay($imgArray) For $i = 1 to UBound($imgArray) step 1 FileWriteLine($myalbum, "<div class='gallery-row'>"&@CRLF) for $z = 1 To 5 FileWriteLine($myalbum, "<div class='gallery-item'><a href='images/full/'"&$imgArray[$i]&"'><img src='images/thumb/'"&$imgArray[$i]&"' alt='' /></a></div> " & @CRLF) Next FileWriteLine($myalbum, "</div>" & @CRLF) Next I would like the images are ordninate numerically and progressively. I hope someone help me. Thanks Edited August 4, 2014 by rootx Link to comment Share on other sites More sharing options...
MikahS Posted August 4, 2014 Share Posted August 4, 2014 Hm, why go backwards in your For loop when you are starting at 1? Try this: For $i = 1 to UBound($imgArray) Step 1 FileWriteLine($myalbum, "<div class='gallery-row'>" & @CRLF) FileWriteLine($myalbum, "<div class='gallery-item'><a href='images/full/'" & $imgArray[$i] & "'><img src='images/thumb/'" & $imgArray[$i] & "' alt='' /></a></div> " & @CRLF) FileWriteLine($myalbum, "</div>" & @CRLF) Next Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
rootx Posted August 4, 2014 Author Share Posted August 4, 2014 The problem is...... the array is not sorted, 1-10-11-.......2-20-21....... to order means .... 1,2,3,4......10,11,12 ..........20,21,21 .... to me has someone already solved a similar problem? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 4, 2014 Moderators Share Posted August 4, 2014 rootx,What you are seeing is the result of the default alphabetic ordering that is used by the sort algorithm in the function - you will see that Windows Explorer orders the files in the same way. You need to convert the string values returned by the function into numbers to sort them as you require. That would be a major undertaking as you would need to extract only the numeric part of the path and somehow link that to the full path after the sort. Another solution would be to pad the smaller numbers with leading "0" characters so that the alphabetic sort does give you the correct order - a simple RegEx will help you there. I will see what I can provide as an example. 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...
Moderators Melba23 Posted August 4, 2014 Moderators Share Posted August 4, 2014 rootx,Here is a simple example to show you how the padding method works:#include <Array.au3> ; What you have now Global $aList[] = ["Path\1.jpg", "Path\10.jpg", "Path\11.jpg", _ "Path\2.jpg", "Path\20.jpg", "Path\21.jpg", _ "Path\3.jpg", "Path\30.jpg", "Path\31.jpg", _ "Path\4.jpg"] _ArrayDisplay($aList, "Original", Default, 8) For $i = 0 To UBound($aList) - 1 $sString = $aList[$i] ; Extract the numeric string before the jpg $sNumeric = StringRegExpReplace($sString, "^.*\\(\d+)\..*$", "$1") ; Padd with leading 0s $sPadded = StringFormat("%03s", $sNumeric) ; Replace the value $sReplace = StringReplace($sString, "\" & $sNumeric & ".", "\" & $sPadded & ".") ; Replace the element $aList[$i] = $sReplace Next _ArrayDisplay($aList, "Padded", Default, 8) _ArraySort($aList) _ArrayDisplay($aList, "Sorted", Default, 8)Please ask if you have any questions. 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...
rootx Posted August 5, 2014 Author Share Posted August 5, 2014 Perfect explanation!! Thanks Melba23. One more question.... Suppose that.... 001.jpg,1.jpg,01.jpg,2.jpg,3.jpg........etc... if I used your function this would be the result 001.jpg,001.jpg,001.jpg....... I had tried in dos but he skip the numbers!! setlocal EnableDelayedExpansion FOR /F %%a IN ('DIR /b /a-d "C:\images\*.jpg" ') DO ( SET /A sort=10001+%%~Na SET file[!sort!]=%%a ) I decided to rename the files in numerical order and then use your RegExp .... Func renimg() Local $filejpg = FileOpen( $renjpg & "\cmd.bat", 1) FileWrite($filejpg,"@echo off" & @CRLF & "setlocal EnableDelayedExpansion" & @CRLF & 'set i=0' & @CRLF & 'FOR %%a IN (*.jpg) DO (' & @CRLF & 'set /a i+=1' & @CRLF & 'ren %%a !i!.tmp' & @CRLF & ')' & @CRLF & 'ren *.tmp *.jpg' & @CRLF & "exit") FileClose($filejpg) ShellExecute("cmd.bat","",$renjpg,"",@SW_HIDE) GUICtrlSetData($Inprenimg,$renjpg) MsgBox("","",$ID_msgimgrenamed) FileDelete( $renjpg & "\cmd.bat") EndFunc Thank you again 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