Krabax Posted 12 hours ago Posted 12 hours ago Hello, since I almost daily have to rename a lot of folders and other stuff, I wanted to create a tiny script. So it automatically renames them 01, 02, 03 ... 45, 46, etc.. It works absolutely fine, unless I give var1 a value with the InputBox and set it to 2, 3, 4, 5, 6, 7, 8 or 9. Values like 1, 10, 11, etc. work just perfectly fine this way. I tried to set var1 to one of these numbers without InputBox to test it and it worked perfectly fine. var2 accepts any values set with InputBox. I have no clue why it ain't working. I'm a total noob when it comes to programming btw. expandcollapse popupGlobal $var1 = 1 Global $var2 = 0 Global $loop = 0 HotKeySet("{ESC}", "Terminate") HotKeySet("{F7}", "Func1") While 1 sleep(100) WEnd Func Func1() $loop = 0 $var1 = InputBox("Rename", "Number to start?", "1", "", -1, 150) $var2 = InputBox("Rename", "Number to stop?", "", "", -1, 150) While $loop = 0 If $var1 <= $var2 Then Send("{F2}") Sleep(20) If $var1 < 10 Then Send("0") EndIf Send($var1) Sleep(20) Send("{ENTER}") Sleep(20) Send("{DOWN}") $var1 = $var1 + 1 Else $loop = 1 EndIf WEnd EndFunc Func Terminate() Exit EndFunc
ioa747 Posted 8 hours ago Posted 8 hours ago (edited) Your main problem is that $var1, $var2 are not integers but text. expandcollapse popupHotKeySet("{ESC}", "Terminate") HotKeySet("{F7}", "Func1") While 1 Sleep(100) WEnd Func Func1() Local $var1 = InputBox("Rename", "Number to start?", "1", "", -1, 150) Local $var2 = InputBox("Rename", "Number to stop?", "", "", -1, 150) Local $FileName $var1 = Int($var1) ; convert to integer $var2 = Int($var2) ; convert to integer While 1 If $var1 <= $var2 Then $FileName = $var1 If $var1 < 10 Then $FileName = "0" & $var1 ConsoleWrite("$FileName=" & $FileName & @CRLF) ; for debugging purpose only Send("{F2}") Sleep(20) Send($FileName) Sleep(20) Send("{ENTER}") Sleep(20) Send("{DOWN}") $var1 += 1 Sleep(2000) ; for debugging purpose only Else ExitLoop EndIf WEnd EndFunc ;==>Func1 Func Terminate() Exit EndFunc ;==>Terminate Edited 5 hours ago by ioa747 I know that I know nothing
Developers Jos Posted 8 hours ago Developers Posted 8 hours ago Do you really want to use the Windows Explorer rename option and all its risks? Why not simply use the FileMove() functions? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioa747 Posted 7 hours ago Posted 7 hours ago (edited) with the above I just wanted to show you where your script fails as mentioned above by Jos, this is not the best method, especially if the data changes order after each rename Here I have a different, more complex but safer approach. (thanks to the footsteps of the Nine ) This script renames multiple folders selected in an open Windows Explorer window numerically, initiated by pressing F7 and requiring an input for the starting number expandcollapse popup#include <Array.au3> HotKeySet("{ESC}", "Terminate") HotKeySet("{F7}", "Func1") While 1 Sleep(100) WEnd Func Func1() Local $hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then Exit Local $oShell = ObjCreate("Shell.Application") For $oWindow In $oShell.Windows() If $oWindow.HWND = $hExplorer Then ExitLoop Next With $oWindow.Document.SelectedItems() If Not .count Then Exit MsgBox(0, "! Error", "Please select a folder(s)") ConsoleWrite("Items selected: " & .count & @CRLF) Local $aFolder[.count] Local $folderCount = 0 For $i = 0 To .count - 1 ; Check if the selected item is a folder If .item($i).IsFolder Then $aFolder[$folderCount] = .item($i).Path $folderCount += 1 EndIf Next ; Resize the array to the actual number of folders selected ReDim $aFolder[$folderCount] EndWith If $folderCount = 0 Then Exit MsgBox(0, "! Error", "Please select at least one folder") Local $var1 = InputBox("Rename", "Number to start?", "1", "", -1, 150) $var1 = Int($var1) ; convert to integer For $i = 0 To UBound($aFolder) - 1 ; Construct the new folder name Local $FolderName If $var1 < 10 Then $FolderName = StringFormat("%02i", $var1) Else $FolderName = $var1 EndIf ; Rename the folder Local $newFolderPath = StringReplace($aFolder[$i], StringRegExpReplace($aFolder[$i], ".*\\", ""), $FolderName) ; Keep the original path DirMove($aFolder[$i], $newFolderPath, 1) ; 1 = overwrite if the new folder already exists ConsoleWrite("Renamed: " & $aFolder[$i] & " to " & $newFolderPath & @CRLF) $var1 += 1 Next EndFunc ;==>Func1 Func Terminate() Exit EndFunc ;==>Terminate Edited 7 hours ago by ioa747 I know that I know nothing
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