
SmartiePants
Members-
Posts
14 -
Joined
-
Last visited
Everything posted by SmartiePants
-
This script (still in testing form) eats 2 .ini configuration files and synchronizes their contents into a new .ini without overwriting any existing values for keys present in both ini's. Later on something like BeyondCompare could be used to check results. #include <array.au3> Global $arrCommonSecs[1] Global $arrUniqueSecsLeft[1] Global $arrUniqueSecsRight[1] Global $iniOut = "iniOut.ini" Global $iniOut_old = "iniOut_old.ini" Global $check = 0 ; debug Global $dumpBoth = "dumpCommonSections.txt" Global $dumpUniqueLeft = "dumpUniqueSectionsLeft.txt" Global $dumpUniqueRight = "dumpUniqueSectionsRight.txt" ; end debug $iniLeft = FileOpenDialog("Select ini 1", @ScriptDir, "All (*.*)", 1) If @error Then Exit $iniRight = FileOpenDialog("Select ini 2", @ScriptDir, "All (*.*)", 1) If @error Then Exit $arrSecNamesLeft = IniReadSectionNames($iniLeft) $arrSecNamesRight = IniReadSectionNames($iniRight) For $i = 1 To $arrSecNamesLeft[0] For $j = 1 To $arrSecNamesRight[0] If $arrSecNamesRight[$j] = $arrSecNamesLeft[$i] Then _ArrayAdd($arrCommonSecs, $arrSecNamesRight[$j]) ExitLoop EndIf Next Next $arrCommonSecs[0] = UBound($arrCommonSecs) - 1 If FileExists(@ScriptDir & "\" & $iniOut) Then ; backup old iniout $filecopy = FileMove(@ScriptDir & "\" & $iniOut, @ScriptDir & "\" & $iniOut_old, 1) If $filecopy = 0 Then MsgBox(64, "Error 1.a", "Failed to backup old ini out") Exit 1 EndIf EndIf $filecopy = FileCopy($iniLeft, @ScriptDir & "\" & $iniOut, 0) ; use a copy of left ini as new iniout If $filecopy = 0 Then MsgBox(64, "Error 1.b", "Failed to copy first ini") Exit 1 EndIf WriteCommonSecs() ArrayToFileDumper($dumpBoth, $arrCommonSecs) ; debug For $i = 1 To $arrSecNamesLeft[0] $check = 0 For $j = 1 To $arrCommonSecs[0] If $arrCommonSecs[$j] = $arrSecNamesLeft[$i] Then $check = 1 ExitLoop EndIf Next If $check = 0 Then _ArrayAdd($arrUniqueSecsLeft, $arrSecNamesLeft[$i]) Next $arrUniqueSecsLeft[0] = UBound($arrUniqueSecsLeft) - 1 For $i = 1 To $arrUniqueSecsLeft[0] ; write unique sections to ini $arrSection = IniReadSection($iniLeft, $arrUniqueSecsLeft[$i]) IniWriteSection($iniOut, $arrUniqueSecsLeft[$i], $arrSection) Next ArrayToFileDumper($dumpUniqueLeft, $arrUniqueSecsLeft) ; debug For $i = 1 To $arrSecNamesRight[0] $check = 0 For $j = 1 To $arrCommonSecs[0] If $arrCommonSecs[$j] = $arrSecNamesRight[$i] Then $check = 1 ExitLoop EndIf Next If $check = 0 Then _ArrayAdd($arrUniqueSecsRight, $arrSecNamesRight[$i]) Next $arrUniqueSecsRight[0] = UBound($arrUniqueSecsRight) - 1 For $i = 1 To $arrUniqueSecsRight[0] ; write unique sections to ini $arrSection = IniReadSection($iniRight, $arrUniqueSecsRight[$i]) IniWriteSection($iniOut, $arrUniqueSecsRight[$i], $arrSection) Next ArrayToFileDumper($dumpUniqueRight, $arrUniqueSecsRight) ; debug Func WriteCommonSecs() Local $test = 0 Local $arrSecLeft[1] Local $arrSecRight[1] For $i = 1 To $arrCommonSecs[0] ; merge keys for dupe entries from 2nd ini to a copy of the first one $arrSecLeft = IniReadSection($iniLeft, $arrCommonSecs[$i]) $arrSecRight = IniReadSection($iniRight, $arrCommonSecs[$i]) If IsArray($arrSecRight) And IsArray($arrSecLeft) Then For $j = 1 To $arrSecRight[0][0] For $k = 1 To $arrSecLeft[0][0] ;ToolTip("$j " & $j & " of " & $arrSecRight[0][0] & "| $k " & $k & " of " & $arrSecLeft[0][0], 300, 0) If $arrSecRight[$j][0] = $arrSecLeft[$k][0] Then ; keys match within section, check if left is blank, otherwise leave as is If Not $arrSecRight[$j][1] = $arrSecLeft[$k][1] Then ; if values don't match If StringLen($arrSecLeft[$k][1]) = 0 And StringLen($arrSecRight[$j][1]) > 0 Then $write = IniWrite($iniOut, $arrCommonSecs[$i], $arrSecRight[$j][0], $arrSecRight[$j][1]) If $write = 0 Then MsgBox(64, "Error 2", "Couldn't write new value for existing key to existing section") Exit 1 EndIf EndIf EndIf $test = 1 ExitLoop Else ; keys don't match $test = 0 EndIf Next If $test = 0 Then ; new key ;ToolTip("$j " & $j & " of " & $arrSecLeft[0][0] & "| $k " & $test & " of " & $arrSecRight[0][0],300,0) $write = IniWrite($iniOut, $arrCommonSecs[$i], $arrSecRight[$j][0], $arrSecRight[$j][1]) If $write = 0 Then MsgBox(64, "Error 3", "Couldn't write new key to existing section") Exit 1 EndIf EndIf Next ElseIf IsArray($arrSecRight) Then ; first ini has no keys under section name For $l = 1 To $arrSecRight[0][0] $write = IniWrite($iniOut, $arrCommonSecs[$i], $arrSecRight[$l][0], $arrSecRight[$l][1]) If $write = 0 Then MsgBox(64, "Error 4", "Couldn't batch write new keys to existing empty section") Exit 1 EndIf Next EndIf Next EndFunc ;==>WriteCommonSecs Func ArrayToFileDumper($zfile, ByRef $zdump) $hwnd = FileOpen(@ScriptDir & "\" & $zfile, 2) ; array dump For $i = 1 To $zdump[0] FileWriteLine($hwnd, $zdump[$i]) Next FileClose($hwnd) EndFunc ;==>ArrayToFileDumper
-
Delete lines from text file by string match
SmartiePants replied to SmartiePants's topic in AutoIt Example Scripts
I like array approach too, and I use it for almost everything I create, but I wanted to make a script quicker and thought my 453 millisecond processing of a 3500 line text file was pretty good. I am suprised with the For $_Element In $_Array line, which ends up requring the $_Item counter. I am used to For $i = 1 to $_Array[0]. This is an interesting approach with fewer lines of code than my average array script. Thanks -
I wanted to find a code on here, but everyone was posting their non-working scripts and I couldn't find a good working one, so I made a simple script on my own. ; DeleteLine.au3 by SmartiePants ; Will read input in Read Only mode, so it will not be altered. ; will output 2 files based on input file by appending new name to the old file name ; will overwrite output files if script is run more than once on the same input file $prompt = FileOpenDialog("Open text file", @WorkingDir, "All (*.*)", 3) If @error = 1 Then Exit; cancelled ; Static filename for output files $outputGood = $prompt & ".good_lines.txt" ; Lines that did not have the string within them $outputBad = $prompt & ".bad_lines.txt" $handleInputFile = FileOpen($prompt, 0) ; open the file in read-only mode If $handleInputFile = -1 Then MsgBox(16, "Error", "Unable to open input text file.") Exit EndIf $string = InputBox("", "Lines with this string will be deleted", "-thumb-") If $string = "" Then MsgBox(16, "Error", "String can't be empty.") Exit EndIf $handleGoodOutput = FileOpen($outputGood, 2) ; overwrite destination file if exists If $handleGoodOutput = -1 Then MsgBox(16, "Error", "Unable to create output text file.") Exit EndIf $handleBadOutput = FileOpen($outputBad, 2) ; overwrite destination file if exists If $handleBadOutput = -1 Then MsgBox(16, "Error", "Unable to create output text file.") Exit EndIf $time = TimerInit() While 1 $line = FileReadLine($handleInputFile) ; read next line If @error = -1 Then ExitLoop ; exit at EOF If Not StringInStr($line, $string) Then FileWriteLine($handleGoodOutput, $line) ; write good lines Else FileWriteLine($handleBadOutput, $line) ; write bad lines EndIf WEnd FileClose($handleInputFile) FileClose($handleGoodOutput) FileClose($handleBadOutput) MsgBox(64, "Done", "in " & Round(TimerDiff($time), 0) & "ms")
-
Change log: Here, it takes a FEW seconds to load because of the hotkey assignments am guessing and is not very organized. I am feeling lazy now, when it just works. You'll probably be surprised when you try it. I do not know how performance will be affected when you manage to 'tag' 1000 images, or some other huge number, since the script performs an array search (on full file path for now because am lazy) to check if current image is already tagged. I added timers to see how long it takes to perform some actions, while I was comparing performance of the two scripts. Known Bugs: There might be a glitch if user types when there are CAPS in the folder name, and shift key gets stuck in the down state. Why I like it: I really like the idea that you can sort your images by pressing ONE key, not having to load every stinkin' image into a realllllllly slow program such as Picasa or My Photo Index, to only find out that you have to type your tags each time, or drag a tag onto each photo within a poorly designed GUI, AFTER those programs display EVERY single filename and/or image you are importing, thus slowing down the import to a crawl. Smart programmers? I think not. It surprises me that no program allows you to do what this post mentions. I am going to make a script to work with XnView. XnView is a robust solution, as opposed to windows picture and fax viewer to display images quickly. Also, XnView can display full file path in the title bar, unlike windows picture and fax viewer. Requirements: Full file path should be set under Tools>Options>View>Title Bar: <Directory><Filename With Ext> Title should look like this: XnView - [K:\random pics\c33a32.jpg] Also in XnView you must set keyboard/mouse to use left/right arrow keys to move between files, which I might include in the script later on. Tools>Options>General:Keyboard/Mouse>Cursor Left/Right>Previous/Next File To use Flavor 1, you must get the OnEventFunc UDF and throw it into AutoIt's Include dir. (LINK)OnEventFunc Downloader which came from ; ImgTag.au3 Flavor 1 by SmartiePants, implementing OnEventFunc UDF by Martin Gibson (martin) ; OnEventFunc is a UDF to allow onevent or HotKeys to be used to call functions with parameters. ; For thread where this udf is posted, see ; http://www.autoitscript.com/forum/topic/71811-functions-with-parameters-in-onevent-and-hotkeys ; ; designed to work within one photo dir per task ; multiple dirs will result something like this - K:\dir1\file1.jpg and K:\dir2\file2.jpg moved to K:\dir1\x\file1.jpg and K:\dir2\x\file2.jpg ; you CAN type outside of the program, but don't do it too fast if you want to avoid keystrokes you didn't intend for. #include <onEventFunc.au3> $tstart = TimerInit() Opt("WinTitleMatchMode", 2) ; 2 = Match any substring in the title Global $sWinTitle = "", $moveto = "", $pos = 0, $ini = @ScriptDir & "\ImgTag.ini" ; declare vars If Not FileExists($ini) Then _iniCreate(); create .ini if it doesn't exist If Not WinExists("XnView -") Then ; exit if XnView isn't running MsgBox(48, "Error 2", "You should have XnView running.") Exit 1 EndIf If Not WinActive("XnView -") Then ; bring XnView forward if it's elsewhere WinActivate("XnView -") WinWaitActive("XnView -") EndIf $aKeys = IniReadSection($ini, "Main") ; read all .ini entries that contain '=' For $i = 1 To $aKeys[0][0] - 1 ; clear invalid entries, do not use _ArrayDelete, since it causes ExitLoop If StringLeft($aKeys[$i][0], 1) = "#" Then $aKeys[$i][0] = "" $aKeys[$i][1] = "" EndIf Next BlockInput(1) For $i = 1 To $aKeys[0][0] - 1 ; set hotkeys Switch $aKeys[$i][0] Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" SetOnEventA($aKeys[$i][0], "_hotkey", $ParamByVal, $aKeys[$i][1]) Case "next_key" Global $next_key = $aKeys[$i][1] HotKeySet($next_key, "_next") Case "previous_key" ; no next_previous_display because it's not shown Global $previous_key = $aKeys[$i][1] HotKeySet($previous_key, "_previous") Case "next_previous_display" ; shown to make the user use right and left arrows Global $next_previous_display = $aKeys[$i][1] Case "move_photos_key" Global $move_photos_key = $aKeys[$i][1] HotKeySet($move_photos_key, "_move") Case "move_photos_key_display" Global $move_photos_key_display = $aKeys[$i][1] EndSwitch Next BlockInput(0) ; Initialize array Local $array[10][2] ; create 2D array that is incremented by 10 elements at a time $array[0][0] = 0 ; [0][0] = count $array[0][1] = UBound($array) ; [0][1] = limit Const $oConst = $array[0][1] $telapsed = TimerDiff($tstart) ToolTip("Started in " & Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | to display next/previous image - " & $next_previous_display, 300, 0) While 1 ; run until Moving Execution Sleep(100) WEnd Func _next() If WinActive("XnView - [") Then BlockInput(1) $tstart = TimerInit() $pos = 0 HotKeySet($next_key) ; temporarily disable Send("{RIGHT}") HotKeySet($next_key, "_next") For $a = $array[0][0] To 1 Step -1 $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window If Not $sWinTitle = 0 Then ; if XnView is running and a file is open... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg If $array[$a][0] = $sWinTitle Then $pos = $a $locFileName = StringInStr($array[$a][0], "\", 2, -1) ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0) ExitLoop EndIf EndIf Next If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) BlockInput(0) EndIf EndFunc ;==>_next Func _previous() If WinActive("XnView - [") Then BlockInput(1) $tstart = TimerInit() $pos = 0 HotKeySet("{LEFT}") ; temporarily disable Send("{LEFT}") HotKeySet("{LEFT}", "_previous") For $a = $array[0][0] To 1 Step -1 $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window If Not $sWinTitle = 0 Then ; if XnView is running and a file is open... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg If $array[$a][0] = $sWinTitle Then $pos = $a $locFileName = StringInStr($array[$a][0], "\", 2, -1) ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0) ExitLoop EndIf EndIf Next If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) BlockInput(0) EndIf EndFunc ;==>_previous Func LogFile($moveto) BlockInput(1) $tstart = TimerInit() $sWinTitle = WinGetTitle("XnView - [") ; Get the full title of the photo viewer window If Not StringInStr($sWinTitle, "\]", 2) Then ; if XnView is running and a file is open... If StringInStr($sWinTitle, ":") Then ; if file path is shown in the title bar... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg $locFileName = StringInStr($sWinTitle, "\", 2, -1) If $array[$array[0][0]][0] = $sWinTitle And $array[$array[0][0]][1] = $moveto Then ; erase tag if setting second time the same, last entry $array[$array[0][0]][0] = "" $array[$array[0][0]][1] = "" ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) ElseIf $pos = 0 Then ; if not the same entry, write new entry If $array[0][0] = $array[0][1] - 1 Then ; resize array $array[0][1] += $oConst ReDim $array[$array[0][1]][2] EndIf $array[0][0] += 1 ; write new entry $array[$array[0][0]][0] = $sWinTitle $array[$array[0][0]][1] = $moveto ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0) Else ; $pos was set, change existing entry If $array[$pos][0] = $sWinTitle And $array[$pos][1] = $moveto Then ; erase entry if setting second time the same, not last entry $array[$pos][0] = "" $array[$pos][1] = "" ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) Else ; update existing entry $array[$pos][0] = $sWinTitle $array[$pos][1] = $moveto ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0) EndIf $pos = 0 ; reset existing entry position after updating entry EndIf Else ; full file path isn't enabled BlockInput(0) MsgBox(48, "Error 4", "Must display full file path in the title bar:" & @CRLF & "Tools>Options>View>Title Bar: <Directory><Filename With Ext>") EndIf Else ; image isn't open BlockInput(0) MsgBox(48, "Error 3", "You should double-click on an image within XnView to cause XnView to display its filename in the title bar.") EndIf BlockInput(0) EndFunc ;==>LogFile Func _move() If $array[0][0] < $array[0][1] Then ; Array trim to valid elements ReDim $array[$array[0][0] + 1][2] EndIf ;_ArrayDisplay($array) ; preview array before moving files for debugging purposes For $i = 1 To $array[0][0] $locFileName = StringInStr($array[$i][0], "\", 2, -1) If FileExists($array[$i][0]) Then ; move all valid files $moved = FileMove($array[$i][0], StringLeft($array[$i][0], $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName), 8) ; 8 = create dir structure If $moved = 0 Then MsgBox(48, "Error 1", "couldn't move " & $array[$i][0] & @CRLF & "to " & StringLeft($array[$i][0], StringLen($array[$i][0]) - $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName)) EndIf ToolTip("Moving " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName), 300, 0) EndIf Next ;~ MsgBox(32, "Done?", "Yeah, ImgTag task completed, photos moved.") ToolTip("Files moved", 300, 0) Exit 0 EndFunc ;==>_move Func _hotkey($key);,$b) If WinActive("XnView - [") Then LogFile($key) Else Ascii($key) EndIf EndFunc ;==>_hotkey Func Ascii($text) $aSplit = StringSplit($text, "") For $i = 1 To $aSplit[0] Local $asc = "{ASC " & Asc($aSplit[$i]) & "}" Send($asc) Next EndFunc ;==>Ascii Func _iniCreate() ToolTip("Creating .INI", 300, 0) $iniHanle = FileOpen($ini, 1) If $iniHanle = -1 Then MsgBox(16, "Error", "Unable to create .INI file") Exit 1 EndIf FileWriteLine($iniHanle, "[Main]") FileWriteLine($iniHanle, "# to put images into dir '99'") FileWriteLine($iniHanle, "# a=99") FileWriteLine($iniHanle, "# to put images into dir 'ZOMG'") FileWriteLine($iniHanle, "# a=ZOMG") FileWriteLine($iniHanle, "# not all hotkeys will be usable, if the program has them assigned internally already.") FileWriteLine($iniHanle, "# use right arrow key to move between photos to update tooltip, or change it to w/e you want, such as {SPACE}") FileWriteLine($iniHanle, "next_key={RIGHT}") FileWriteLine($iniHanle, "previous_key={LEFT}") FileWriteLine($iniHanle, "next_previous_display=Left/Right Arrow keys") FileWriteLine($iniHanle, "# ^ - control, ! - alt, + - shift") FileWriteLine($iniHanle, "move_photos_key=^!y") FileWriteLine($iniHanle, "move_photos_key_display=Ctrl+Alt+Y") FileWriteLine($iniHanle, "1=1") FileWriteLine($iniHanle, "2=2") FileWriteLine($iniHanle, "3=3") FileWriteLine($iniHanle, "4=4") FileWriteLine($iniHanle, "5=5") FileWriteLine($iniHanle, "6=6") FileWriteLine($iniHanle, "7=7") FileWriteLine($iniHanle, "8=8") FileWriteLine($iniHanle, "9=9") FileWriteLine($iniHanle, "0=0") FileWriteLine($iniHanle, "a=a") FileWriteLine($iniHanle, "b=b") FileWriteLine($iniHanle, "c=c") FileWriteLine($iniHanle, "d=d") FileWriteLine($iniHanle, "e=e") FileWriteLine($iniHanle, "f=f") FileWriteLine($iniHanle, "g=g") FileWriteLine($iniHanle, "h=h") FileWriteLine($iniHanle, "i=i") FileWriteLine($iniHanle, "j=j") FileWriteLine($iniHanle, "k=k") FileWriteLine($iniHanle, "l=l") FileWriteLine($iniHanle, "m=m") FileWriteLine($iniHanle, "n=n") FileWriteLine($iniHanle, "o=o") FileWriteLine($iniHanle, "p=p") FileWriteLine($iniHanle, "q=q") FileWriteLine($iniHanle, "r=r") FileWriteLine($iniHanle, "s=s") FileWriteLine($iniHanle, "t=t") FileWriteLine($iniHanle, "u=u") FileWriteLine($iniHanle, "v=v") FileWriteLine($iniHanle, "w=w") FileWriteLine($iniHanle, "x=x") FileWriteLine($iniHanle, "y=y") FileWriteLine($iniHanle, "z=z") FileClose($iniHanle) MsgBox(32, "Should you review .ini?", "Sure, review .ini" & @CRLF & "When done, close notepad to resume script.") ShellExecuteWait("Notepad.exe", $ini, @ScriptDir, "open", @SW_MAXIMIZE)EndFunc ;==>_iniCreate ; ImgTag.au3 Flavor 2 by SmartiePants, implementing @HotKeyPressed ; ; designed to work within one photo dir per task ; multiple dirs will result something like this - K:\dir1\file1.jpg and K:\dir2\file2.jpg moved to K:\dir1\x\file1.jpg and K:\dir2\x\file2.jpg ; you CAN type outside of the program, but don't do it too fast if you want to avoid keystrokes you didn't intend for. #include <Misc.au3> $tstart = TimerInit() Opt("WinTitleMatchMode", 2) ; 2 = Match any substring in the title Global $sWinTitle = "", $moveto = "", $pos = 0, $ini = @ScriptDir & "\ImgTag.ini" ; declare vars If Not FileExists($ini) Then _iniCreate(); create .ini if it doesn't exist If Not WinExists("XnView -") Then ; exit if XnView isn't running MsgBox(48, "Error 2", "You should have XnView running.") Exit 1 EndIf If Not WinActive("XnView -") Then ; bring XnView forward if it's elsewhere WinActivate("XnView -") WinWaitActive("XnView -") EndIf $aKeys = IniReadSection($ini, "Main") ; read all .ini entries that contain '=' For $i = 1 To $aKeys[0][0] - 1 ; clear invalid entries, do not use _ArrayDelete, since it causes ExitLoop If StringLeft($aKeys[$i][0], 1) = "#" Then $aKeys[$i][0] = "" $aKeys[$i][1] = "" EndIf Next BlockInput(1) For $i = 1 To $aKeys[0][0] - 1 ; set hotkeys Switch $aKeys[$i][0] Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" HotKeySet($aKeys[$i][0], "_hotkey") ; set all alphanumeric HotKey presets from .ini Case "next_key" Global $next_key = $aKeys[$i][1] HotKeySet($next_key, "_next") Case "previous_key" ; no next_previous_display because it's not shown Global $previous_key = $aKeys[$i][1] HotKeySet($previous_key, "_previous") Case "next_previous_display" ; shown to make the user use right and left arrows Global $next_previous_display = $aKeys[$i][1] Case "move_photos_key" Global $move_photos_key = $aKeys[$i][1] HotKeySet($move_photos_key, "_move") Case "move_photos_key_display" Global $move_photos_key_display = $aKeys[$i][1] EndSwitch Next BlockInput(0) ; Initialize array Local $array[10][2] ; create 2D array that is incremented by 10 elements at a time $array[0][0] = 0 ; [0][0] = count $array[0][1] = UBound($array) ; [0][1] = limit Const $oConst = $array[0][1] ToolTip("Started in " & Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | to display next/previous image - " & $next_previous_display, 300, 0) While 1 ; run until Moving Execution Sleep(100) WEnd Func _next() If WinActive("XnView - [") Then BlockInput(1) $tstart = TimerInit() $pos = 0 HotKeySet($next_key) ; temporarily disable Send("{RIGHT}") HotKeySet($next_key, "_next") For $a = $array[0][0] To 1 Step -1 $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window If Not $sWinTitle = 0 Then ; if XnView is running and a file is open... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg If $array[$a][0] = $sWinTitle Then $pos = $a $locFileName = StringInStr($array[$a][0], "\", 2, -1) ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0) ExitLoop EndIf EndIf Next If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) BlockInput(0) EndIf EndFunc ;==>_next Func _previous() If WinActive("XnView - [") Then BlockInput(1) $tstart = TimerInit() $pos = 0 HotKeySet("{LEFT}") ; temporarily disable Send("{LEFT}") HotKeySet("{LEFT}", "_previous") For $a = $array[0][0] To 1 Step -1 $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window If Not $sWinTitle = 0 Then ; if XnView is running and a file is open... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg If $array[$a][0] = $sWinTitle Then $pos = $a $locFileName = StringInStr($array[$a][0], "\", 2, -1) ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0) ExitLoop EndIf EndIf Next If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) BlockInput(0) EndIf EndFunc ;==>_previous Func LogFile($moveto) BlockInput(1) $tstart = TimerInit() $sWinTitle = WinGetTitle("XnView - [") ; Get the full title of the photo viewer window If Not StringInStr($sWinTitle, "\]", 2) Then ; if XnView is running and a file is open... If StringInStr($sWinTitle, ":") Then ; if file path is shown in the title bar... $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg] $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg $locFileName = StringInStr($sWinTitle, "\", 2, -1) If $array[$array[0][0]][0] = $sWinTitle And $array[$array[0][0]][1] = $moveto Then ; erase tag if setting second time the same, last entry $array[$array[0][0]][0] = "" $array[$array[0][0]][1] = "" ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) ElseIf $pos = 0 Then ; if not the same entry, write new entry If $array[0][0] = $array[0][1] - 1 Then ; resize array $array[0][1] += $oConst ReDim $array[$array[0][1]][2] EndIf $array[0][0] += 1 ; write new entry $array[$array[0][0]][0] = $sWinTitle $array[$array[0][0]][1] = $moveto ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0) Else ; $pos was set, change existing entry If $array[$pos][0] = $sWinTitle And $array[$pos][1] = $moveto Then ; erase entry if setting second time the same, not last entry $array[$pos][0] = "" $array[$pos][1] = "" ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0) Else ; update existing entry $array[$pos][0] = $sWinTitle $array[$pos][1] = $moveto ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0) EndIf $pos = 0 ; reset existing entry position after updating entry EndIf Else ; full file path isn't enabled BlockInput(0) MsgBox(48, "Error 4", "Must display full file path in the title bar:" & @CRLF & "Tools>Options>View>Title Bar: <Directory><Filename With Ext>") EndIf Else ; image isn't open BlockInput(0) MsgBox(48, "Error 3", "You should double-click on an image within XnView to cause XnView to display its filename in the title bar.") EndIf BlockInput(0) EndFunc ;==>LogFile Func _move() If $array[0][0] < $array[0][1] Then ; Array trim to valid elements ReDim $array[$array[0][0] + 1][2] EndIf ;_ArrayDisplay($array) ; preview array before moving files for debugging purposes For $i = 1 To $array[0][0] $locFileName = StringInStr($array[$i][0], "\", 2, -1) If FileExists($array[$i][0]) Then ; move all valid files $moved = FileMove($array[$i][0], StringLeft($array[$i][0], $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName), 8) ; 8 = create dir structure If $moved = 0 Then MsgBox(48, "Error 1", "couldn't move " & $array[$i][0] & @CRLF & "to " & StringLeft($array[$i][0], StringLen($array[$i][0]) - $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName)) EndIf ToolTip("Moving " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName), 300, 0) EndIf Next ;~ MsgBox(32, "Done?", "Yeah, ImgTag task completed, photos moved.") ToolTip("Files moved", 300, 0) Exit 0 EndFunc ;==>_move Func _hotkey() ; for now repetitive array search For $i = 1 To $aKeys[0][0] If $aKeys[$i][0] = @HotKeyPressed Then Local $dir = $aKeys[$i][1] ExitLoop EndIf Next If WinActive("XnView - [") Then LogFile($dir) Else Ascii($dir) EndIf EndFunc ;==>_hotkey Func Ascii($text) $aSplit = StringSplit($text, "") For $i = 1 To $aSplit[0] Local $asc = "{ASC " & Asc($aSplit[$i]) & "}" Send($asc) Next EndFunc ;==>Ascii Func _iniCreate() ToolTip("Creating .INI", 300, 0) $iniHanle = FileOpen($ini, 1) If $iniHanle = -1 Then MsgBox(16, "Error", "Unable to create .INI file") Exit 1 EndIf FileWriteLine($iniHanle, "[Main]") FileWriteLine($iniHanle, "# to put images into dir '99'") FileWriteLine($iniHanle, "# a=99") FileWriteLine($iniHanle, "# to put images into dir 'ZOMG'") FileWriteLine($iniHanle, "# a=ZOMG") FileWriteLine($iniHanle, "# not all hotkeys will be usable, if the program has them assigned internally already.") FileWriteLine($iniHanle, "# use right arrow key to move between photos to update tooltip, or change it to w/e you want, such as {SPACE}") FileWriteLine($iniHanle, "next_key={RIGHT}") FileWriteLine($iniHanle, "previous_key={LEFT}") FileWriteLine($iniHanle, "next_previous_display=Left/Right Arrow keys") FileWriteLine($iniHanle, "# ^ - control, ! - alt, + - shift") FileWriteLine($iniHanle, "move_photos_key=^!y") FileWriteLine($iniHanle, "move_photos_key_display=Ctrl+Alt+Y") FileWriteLine($iniHanle, "1=1") FileWriteLine($iniHanle, "2=2") FileWriteLine($iniHanle, "3=3") FileWriteLine($iniHanle, "4=4") FileWriteLine($iniHanle, "5=5") FileWriteLine($iniHanle, "6=6") FileWriteLine($iniHanle, "7=7") FileWriteLine($iniHanle, "8=8") FileWriteLine($iniHanle, "9=9") FileWriteLine($iniHanle, "0=0") FileWriteLine($iniHanle, "a=a") FileWriteLine($iniHanle, "b=b") FileWriteLine($iniHanle, "c=c") FileWriteLine($iniHanle, "d=d") FileWriteLine($iniHanle, "e=e") FileWriteLine($iniHanle, "f=f") FileWriteLine($iniHanle, "g=g") FileWriteLine($iniHanle, "h=h") FileWriteLine($iniHanle, "i=i") FileWriteLine($iniHanle, "j=j") FileWriteLine($iniHanle, "k=k") FileWriteLine($iniHanle, "l=l") FileWriteLine($iniHanle, "m=m") FileWriteLine($iniHanle, "n=n") FileWriteLine($iniHanle, "o=o") FileWriteLine($iniHanle, "p=p") FileWriteLine($iniHanle, "q=q") FileWriteLine($iniHanle, "r=r") FileWriteLine($iniHanle, "s=s") FileWriteLine($iniHanle, "t=t") FileWriteLine($iniHanle, "u=u") FileWriteLine($iniHanle, "v=v") FileWriteLine($iniHanle, "w=w") FileWriteLine($iniHanle, "x=x") FileWriteLine($iniHanle, "y=y") FileWriteLine($iniHanle, "z=z") FileClose($iniHanle) MsgBox(32, "Should you review .ini?", "Sure, review .ini" & @CRLF & "When done, close notepad to resume script.") ShellExecuteWait("Notepad.exe", $ini, @ScriptDir, "open", @SW_MAXIMIZE) EndFunc ;==>_iniCreate
-
Code looks fancy... fancy enough to be out of my lead. =P (See, I commented =)
-
Well, it seems I can't create a coherent means of displaying the locations of found numbers so that the user can select what shall be enumerated. I tried to make a GUI, but saw the shortcoming of control generation, as their names should be hard-coded. I thought of using an IE window with proper javascript because it is much easier to display elements in a web page than in a GUI, but javascript must store values in some hidden element within the webpage, which can later be read. I guess my only problem is having those "hidden" values stored somewhere by javascript. here is the script code with added GUI that I have added so far. If someone has great ideas on how I should display the found number locations, speak your mind. Thanks. #include <GUIConstants.au3> #include <IE.au3> ; plans: to enable $numSelect input to be of 7-1,14-4 format ; where 7 is the starting character for # to enumerate and 1 is the number of characters that should be enumerated, ; thus forcing the digit enumeration to a specific section instead of the whole # within the link. AutoItSetOption("TrayIconHide", 1) ToolTip("http://www.russki-razmer.spb.ru/photo/1.jpg" & @CR & "Note: make sure # starts with smallest available, normally 1, such as the 1.jpg", 300, 0, "Base link example:") $lnkInput = InputBox("Base Link", "Enter base link for enumeration", "", "", 300, 115) If $lnkInput = "" Then Exit ToolTip(@ScriptDir & "\LinkOut.txt", 300, 0, "Output file will be...") $len = StringSplit($lnkInput, "") Global $arrOccurence[$len[0] + 1][2] Global $arrNum[1][2] Global $strOutput = "" $arrOccurence[0][0] = $len[0] For $l = 1 To $len[0] Switch $len[$l] Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" $numChk = 1 Case Else $numChk = 0 EndSwitch If Not $numChk = 0 Then $arrOccurence[$l][0] = 1 Else $arrOccurence[$l][0] = 0 EndIf Next $c = 1; check if 1st dim has 1 and store # in 2nd dim For $o = 1 To $arrOccurence[0][0]; - 1 $arrOccurence[$o][1] = 0 If $arrOccurence[$o][0] = 1 Then $arrOccurence[$c][1] += 1 Else $c = $o + 1 EndIf Next $r = 1 For $n = 1 To $arrOccurence[0][0] - 1 If $arrOccurence[$n][1] > 0 Then $r += 1 ReDim $arrNum[$r][2] $arrNum[$r - 1][0] = $n; location of # start $arrNum[$r - 1][1] = $arrOccurence[$n][1]; number of #'s EndIf Next $arrNum[0][0] = UBound($arrNum) $moo = 0 $cow = 0 ; ########### temporary solution ######### For $p = 1 To $arrNum[0][0] - 1 If $moo = 0 Then For $y = 1 To $arrNum[$p][0] - 1 $cow = $arrNum[$p][0] $strOutput = $strOutput & ".";Chr(32) Next Else For $y = 1 To $arrNum[$p][0] - 1 $cow1 = $arrNum[$p][0] Next For $y = 1 To $cow1 - $cow $strOutput = $strOutput & ".";Chr(32) Next EndIf $strOutput = $strOutput & $arrNum[$p][0] For $z = $arrNum[$p][0] To $arrNum[$p][0] + $arrNum[$p][1] - 1 $strOutput = $strOutput & "-";Chr(32) Next $strOutput = $strOutput & $arrNum[$p][1] $moo += 1 Next ToolTip("Ex. calculation of # locations: .....7-1.....15-4" & @CR & "7 and 15 are starting characters" & @CR & "1 and 4 is the amount of characters in the # within the link (ignore them)", 300, 0, "Input the correct occurence that should be enumerated") ; ################### GUI ################## GUICreate("Select Numbers", 800, 120) $oIE = ObjCreate("Shell.Explorer.2") GUICtrlCreateObj($oIE, 0, 0, 800, 56); 56 GUICtrlCreateInput("", 0, 56, 800, 30); 86 $Submit = GUICtrlCreateButton("Enumerate", 0, 86, 800, 34) GUISetState() FileWriteLine("temp.html", '<html><head></head><body bgcolor="black">') ; start element html code For $a = 1 To $len[0] If $arrOccurence[$a][0] = 1 Then FileWrite("temp.html", "<b><font color='green'>" & $len[$a] & "</font></b>") Else FileWrite("temp.html", "<font color='white'>" & $len[$a] & "</font>") EndIf Next ; end element html code FileWrite("temp.html", '</body></html>') $oIE.navigate(@WorkingDir & "\temp.html") _IELoadWait($oIE) Do ; collect hidden IE content and show it in the Inputbox control ;$GuiInput = _IEGetObjByName($oIE, "") $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE FileDelete("temp.html") Exit Case $msg = $Submit ; fix this code FileDelete("temp.html") ExitLoop EndSelect Until 0 ; ##################################### If $arrNum[0][0] > 2 Then $numSelect = InputBox("Input 1st # for selection", $strOutput & @CR & $lnkInput, "", "", 800, 125) If $numSelect = "" Then Exit Else $numSelect = $arrNum[1][0] EndIf $lnkLeft = StringLeft($lnkInput, $numSelect - 1) For $x = 1 To $arrNum[0][0] - 1 If $arrNum[$x][0] = $numSelect Then $limRight = $arrNum[$x][1] EndIf Next $lnkRight = StringRight($lnkInput, StringLen($lnkInput) - ($numSelect + $limRight - 1)) ToolTip("Ex: 100", 300, 0, "You surely want a limit on the # of links generated") $limit = InputBox("Limit", "How many links to generate?", "", "", 300, 125) $lnkNumEnum = StringMid($lnkInput, $numSelect, $limRight) ; if $lnkNumEnum starts with zeros... $numOriginal = $lnkNumEnum $numBase = $numOriginal $numSplit = StringSplit($numOriginal, "") For $s = 1 To $numSplit[0] - 1 If $numSplit[$s] = "0" Then $numLeft = StringLeft($numOriginal, $s) $numBase = StringRight($numOriginal, StringLen($numOriginal) - 1) EndIf Next Global $numLenOld, $numLeft $numBase = Number($numBase) $numLenOld = StringLen($numBase) $fileOutput = FileOpen(@ScriptDir & "\LinkOut.txt", 2) If $fileOutput = -1 Then MsgBox(16, "Error", "Cannot create output file!") Exit EndIf For $j = $lnkNumEnum To $lnkNumEnum + $limit ToolTip("Link #" & $j, 300, 0) $numLen = StringLen($numBase) If $numLen > $numLenOld Then $numLeft = StringLeft($numLeft, StringLen($numLeft) - 1) EndIf $numLenOld = $numLen $numFinal = String($numLeft & $numBase) $numBase += 1 FileWriteLine($fileOutput, $lnkLeft & $numFinal & $lnkRight) Next ToolTip("") FileClose($fileOutput)
-
That is one of the purposes, whereas the other would be to enumerate a number in the middle of the link. Ex: http://www.moocow.com/page1234/1.html - where I want to enumerate only the 1234 portion and not the 1.html I wanted the script to be able to figure out where numbers are and then give the ability to the user to select what should be enumerated. Sort of like human logic as we see a string of text and know that we should only change a specific section of it and leave the rest as is. I think there is more use to such a script than just web links' enumeration I might be able to figure out my own mistakes though...
-
I have put together a somewhat crude script that is supposed to find numbers within the supplied link, tell the user those number locations and prompt which one should be enumerated, meaning the script would generate links with that particular number incremented. script worked well for an example link http://www.russki-razmer.spb.ru/photo/1.jpg but did not for http://www.russki-razmer.spb.ru/photo/pivnoi06/1.jpg - it has a fault with the display of .......#-#..., but that is temporary, for I could not put together a more elaborate solution for display of the found number locations. The main problem is that with 06/1.jpg the script enumerated the / instead of digits... I have spent too much time on it that I can't think straight and was hoping someone could help me a bit Thanks.. Updated code as of ...the time and date of the update of the post It is clumsy, but works. The script figures out locations of the #'s within the string/link supplied, prompts which to enumerate if there is more than 1, then, if the string starts with Zeros (ex: www.moocow.com/0006/index.html), output would yield 0006 to be 0007 instead of just 7, when enumerated # reaches 10, 100, 1000, zeros are displaced to contain less, otherwise the number is simply enumerated to the amount specified by the user in the next step. Hope I said that right.. 4:30am, college in the morning *goes to bed* Anyone is free to simplify my script at the cost of their time and effort and share with me the results ; plans: to enable $numSelect input to be of 7-1,14-4 format ; where 7 is the starting character for # to enumerate and 1 is the number of characters that should be enumerated, ; thus forcing the digit enumeration to a specific section instead of the whole # within the link. AutoItSetOption("TrayIconHide", 1) ToolTip("http://www.russki-razmer.spb.ru/photo/1.jpg" & @CR & "Note: make sure # starts with smallest available, normally 1, such as the 1.jpg", 300, 0, "Base link example:") $lnkInput = InputBox("Base Link", "Enter base link for enumeration", "", "", 300, 115) If $lnkInput = "" Then Exit ToolTip(@ScriptDir & "\LinkOut.txt", 300, 0, "Output file will be...") $len = StringSplit($lnkInput, "") Global $arrOccurence[$len[0] + 1][2] Global $arrNum[1][2] Global $strOutput = "" $arrOccurence[0][0] = $len[0] For $l = 1 To $len[0] Switch $len[$l] Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" $numChk = 1 Case Else $numChk = 0 EndSwitch If Not $numChk = 0 Then $arrOccurence[$l][0] = 1 Else $arrOccurence[$l][0] = 0 EndIf Next $c = 1; check if 1st dim has 1 and store # in 2nd dim For $o = 1 To $arrOccurence[0][0]; - 1 $arrOccurence[$o][1] = 0 If $arrOccurence[$o][0] = 1 Then $arrOccurence[$c][1] += 1 Else $c = $o + 1 EndIf Next $r = 1 For $n = 1 To $arrOccurence[0][0] - 1 If $arrOccurence[$n][1] > 0 Then $r += 1 ReDim $arrNum[$r][2] $arrNum[$r - 1][0] = $n; location of # start $arrNum[$r - 1][1] = $arrOccurence[$n][1]; number of #'s EndIf Next $arrNum[0][0] = UBound($arrNum) For $p = 1 To $arrNum[0][0] - 1 For $y = 1 To $arrNum[$p][0] - 1 $strOutput = $strOutput & ".";Chr(32) Next $strOutput = $strOutput & $arrNum[$p][0] For $z = $arrNum[$p][0] To $arrNum[$p][0] + $arrNum[$p][1] - 1 $strOutput = $strOutput & "-";Chr(32) Next $strOutput = $strOutput & $arrNum[$p][1] Next ToolTip("Ex. calculation of # locations: .....7-1.....15-4" & @CR & "7 and 15 are starting characters" & @CR & "1 and 4 is the amount of characters in the # within the link (ignore them)", 300, 0, "Input the correct occurence that should be enumerated") If $arrNum[0][0] > 2 Then $numSelect = InputBox("Input 1st # for selection", $strOutput & @CR & $lnkInput, "", "", 500, 125) If $numSelect = "" Then Exit Else $numSelect = $arrNum[1][0] EndIf $lnkLeft = StringLeft($lnkInput, $numSelect - 1) For $x = 1 To $arrNum[0][0] - 1 If $arrNum[$x][0] = $numSelect Then $limRight = $arrNum[$x][1] EndIf Next $lnkRight = StringRight($lnkInput, StringLen($lnkInput) - ($numSelect + $limRight - 1)) ToolTip("Ex: 100", 300, 0, "You surely want a limit on the # of links generated") $limit = InputBox("Limit", "How many links to generate?", "", "", 300, 125) $lnkNumEnum = StringMid($lnkInput, $numSelect, $limRight) ; if $lnkNumEnum starts with zeros... $numOriginal = $lnkNumEnum $numBase = $numOriginal $numSplit = StringSplit($numOriginal, "") For $s = 1 To $numSplit[0] - 1 If $numSplit[$s] = "0" Then $numLeft = StringLeft($numOriginal, $s) $numBase = StringRight($numOriginal, StringLen($numOriginal) - 1) EndIf Next Global $numLenOld, $numLeft $numBase = Number($numBase) $numLenOld = StringLen($numBase) $fileOutput = FileOpen(@ScriptDir & "\LinkOut.txt", 2) If $fileOutput = -1 Then MsgBox(16, "Error", "Cannot create output file!") Exit EndIf For $j = $lnkNumEnum To $lnkNumEnum + $limit ToolTip("Link #" & $j, 300, 0) $numLen = StringLen($numBase) If $numLen > $numLenOld Then $numLeft = StringLeft($numLeft, StringLen($numLeft) - 1) EndIf $numLenOld = $numLen $numFinal = String($numLeft & $numBase) $numBase += 1 FileWriteLine($fileOutput, $lnkLeft & $numFinal & $lnkRight) Next ToolTip("") FileClose($fileOutput)
-
I am sorry, I did not have a clear understanding of arrays at the time... Thanks to Paulie, I believe I can understand how arrays work muttley
-
I have an idea, but do not know how to put it to work. I wanted to write a function that would be used by the script to store data in arrays. The conundrum is that I want to create a pretty much unlimited number of arrays with a limit at say... 1000 entries. It seemed simpler in my mind until I threw together this preliminary code: Func WriteArray($FileName) If IsDeclared( String(String($array) & Number($aNum))) and String(String($array) & Number($aNum))[0] < 1000 then; if array is declared and is less than 1000 elements String(String($array) & Number($aNum))[$count] = $FileName $count += 1 String(String($array) & Number($aNum))[0] = UBound(String(String($array) & Number($aNum))[0]) - 1 ElseIf not IsDeclared( String(String($array) & Number($aNum))) then; if array is not declared Dim String(String($array) & Number($aNum))[2] String(String($array) & Number($aNum))[$count] = $FileName $count += 1 String(String($array) & Number($aNum))[0] = UBound(String(String($array) & Number($aNum))[0]) - 1 ElseIf IsDeclared( String(String($array) & Number($aNum))) and String(String($array) & Number($aNum))[0] >= 1000 then; if array is declared and has greater than or equal to 1000 elements $aNum += 1; increase array variable title. Ex: $array1 $count = 1 Dim String(String($array) & Number($aNum))[2] String(String($array) & Number($aNum))[$count] = $FileName $count += 1 String(String($array) & Number($aNum))[0] = UBound(String(String($array) & Number($aNum))[0]) - 1 EndIf ToolTip($FileName,0,0) EndFunc I know the code has many errors and warnings. But the idea is valid. I just do not know how to write a code that would perform what I described above. I have asked a question before on the similar subject, but I was vague and didn't have code. I only came to the functions Eval, IsDeclared and Assign. Hope someone could help me figure this out.. Thanks in advance
-
Variable name generation
SmartiePants replied to SmartiePants's topic in AutoIt General Help and Support
Mmm, I think I will stay away from scripting dictionary for now; it scares me XD I will probably stick to using Eval and simpler code Thanks for the tips guys! -
Variable name generation
SmartiePants replied to SmartiePants's topic in AutoIt General Help and Support
Well, I was thinking yesterday about what I posted here and maybe I can just use 2 arrays and throw data into the main array after working on a small chunk of it in the temporary array. I guess my mind was stuck on the idea where I wanted to have more proficiency by somehow splitting the file into chunks and working on them at the same time, but it is still crazy to do that with my skill, if I can even call that so. Thanks for the Eval! I don't know how I didn't find it in autoit help before -
Hello to anyone who is willing to reply and/or help me with this This is my first post on this forum! I am trying to generate variable names, but having one of those "can't compute" moments. While 1 ($arr & $x)[1] While $n < 3000 $line = FileReadLine($file) If @error = -1 Then ($arr & $x)[0] = UBound(($arr & $x)) - 1 ToolTip("Removing Dupes from array # " & $x, 20, 20, "", 1, 4) _Array1MakeUnique(($arr & $x)) $n = 1 While $x > 0 For $n = 1 To ($arr & $x)[0] ReDim ($arr & $x)[$n + 1] ($arr & $x)[$n] = $line ToolTip($n, 20, 20, "Lines read into main array from array # " & $x, 1, 4) Next $x -= 1 WEnd $arr[0] = UBound($arr) - 1 ExitLoop(2) EndIf ReDim ($arr & $x)[$n + 1] ($arr & $x)[$n] = $line ToolTip($n, 20, 20, "Lines read into array", 1, 4) $n += 1 WEnd ($arr & $x)[0] = UBound(($arr & $x)) - 1 ToolTip("Removing Dupes from array # " & $x, 20, 20, "", 1, 4) _Array1MakeUnique(($arr & $x)) $n = 1 $x += 1 WEnd Code isn't tested since I can't even get the variable declaration going right. I thought that maybe it is possible to do smth like $tmpArr = String("$arr" & $x), but that would just assign a value to that variable, which I don't need at all How would I go about creating legitimate variable titles for my arrays? Btw, the purpose for this script (didn't paste all of it here) is to remove dupes from a 30+MB text file that has quite a mess with dupes. If you have a suggestion that would make this code "simpler", throw it at me too Thanks!