sbrady Posted April 11, 2014 Share Posted April 11, 2014 can someone help me figure out how to rename selected files. Look at the before and after naming conventions. Can anyone help get me started in the right direction. before AR123 Smith, Bob Eye Surgery v1 Full mix.wav AR123 Smith, Bob Eye Surgery v1 SOT mix.wav AR123 Smith, Bob Eye Surgery v1 M&E mix.wav after AR123 Smith, Bob Eye Surgery Full mix v1.wav AR123 Smith, Bob Eye Surgery SOT mix v1.wav AR123 Smith, Bob Eye Surgery M&E mix v1.wav Link to comment Share on other sites More sharing options...
sbrady Posted April 11, 2014 Author Share Posted April 11, 2014 would _ClipPutFile work, could I rename the file when I paste it back? I'm digging for anything that I think might work. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 11, 2014 Share Posted April 11, 2014 The FileMove function can be used to rename a file. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
sbrady Posted April 11, 2014 Author Share Posted April 11, 2014 how about: _WinAPI_GetFileTitle Link to comment Share on other sites More sharing options...
sbrady Posted April 11, 2014 Author Share Posted April 11, 2014 here is some code I have used but I am looking for an easier way. ; START SHAWN's CODE____________________________ ; repeat with the selected items For $File_Name = 1 To $aSelection $result = StringInStr($File_Name, "mix",0,1) If $result > 0 Then $filename2 = StringInStr ( $File_Name, "\" , 0 , -1) ; (last "\" is 47 chars in from righy) $the_folder_path = StringLeft ( $File_Name, $filename2 ) ; C:\Documents and Settings\sebrad\Desktop\shawn\ $file_path_len = StringLen($File_Name) ; 79 total characters $char_in_file_name = $file_path_len - $filename2 ;31 char in file name only $orig_file_name = StringRight ($File_Name, $char_in_file_name) ;AR123 Smith, Bob v1 FULL MIX.txt $new_file_name = StringRegExpReplace($orig_file_name, "(?i)(.*)(\sv.*)(\s.*\sMIX)(\.txt)", "$1$3$2$4") ;AR123 Smith, Bob FULL MIX v1.txt FileCopy ( $File_Name, ($the_folder_path & $new_file_name), 1 ) ; 1 = with overwright FileDelete ( $the_folder_path & $orig_file_name) EndIf Link to comment Share on other sites More sharing options...
sbrady Posted April 11, 2014 Author Share Posted April 11, 2014 is it possible to click on a file and get the file name so I can write code to rename the selected file. Link to comment Share on other sites More sharing options...
jdelaney Posted April 11, 2014 Share Posted April 11, 2014 (edited) Hate to do this to you, but this might be the only way on > windows 7 '?do=embed' frameborder='0' data-embedContent>> You can loop through the list of files on your explorer<UIA_ListItemControlTypeId> When the file is selected, this property is set: UIA_ToggleToggleStatePropertyId :=1 when not selected, this property is set to: UIA_ToggleToggleStatePropertyId :=0 Huge learning curve to get through... You would have a much easier time doing this some other way. Edited April 11, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jdelaney Posted April 11, 2014 Share Posted April 11, 2014 (edited) Here you go...this will cut all the files (only those selected) to another explorer window set for c:testing...you can then loop through that dir, rename ALL your files, and move back to your original file (file* funcitons) $h1 = WinGetHandle("[CLASS:CabinetWClass]") DirCreate("C:\testing") $ipid = Run("explorer c:\testing") Local $h2 $iTimer = TimerInit() While TimerDiff($iTimer)<5000 $a = WinList("[CLASS:CabinetWClass]") If UBound($a)> 2 Then For $i = 1 To UBound($a)-1 If $a[$i][1]<>$h1 Then $h2 = $a[$i][1] ExitLoop 2 EndIf Next EndIf WEnd If Not IsHWnd($h2) Then MsgBox(1,1,"can't find second window") Exit EndIf WinActivate($h1) ControlSend($h1, "","[CLASS:DirectUIHWND; INSTANCE:3]","^x") WinActivate($h2) ControlSend($h2, "","[CLASS:DirectUIHWND; INSTANCE:3]","^v") ConsoleWrite($h1 & " " & $h2) Edited April 11, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
sahsanu Posted April 11, 2014 Share Posted April 11, 2014 is it possible to click on a file and get the file name so I can write code to rename the selected file. Sometime ago, for a similar project, I used the function >_WindowsExplorer_ExtractSelectedDirAndFiles writen by KaFu with very good resuts. The function will return an array with the selected files and it works on Windows XP and 7. I'm in a hurry so I can't write any example but I could write some example later if you have any doubt. Cheers, sahsanu Link to comment Share on other sites More sharing options...
sahsanu Posted April 11, 2014 Share Posted April 11, 2014 Here is a working example to rename your selected wav files. Execute the script -> open an Explorer and select the files you want to rename -> Press Ctrl + Alt + r and if the files have the right pattern, they will be renamed (a backup of the orginial file is saved appending the extension .original) -> to exit the script just press Alt + ESC expandcollapse popupGlobal $aSelected HotKeySet("!{ESC}", "_Exit") ; Alt + ESC to Exit HotKeySet("^!r", "_Selecting") ; Ctrl + Alt + r to rename selected files While 1 Sleep(120000) WEnd Func _Selecting() If WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]") Then $aWinList = WinGetHandle("[REGEXPCLASS:(Explore|Cabinet)WClass]") $aSelected = _WindowsExplorer_ExtractSelectedDirAndFiles($aWinList) If @error Then MsgBox(16, "Error", "An error occurred trying to get selected files.") ElseIf $aSelected[0] = 0 Then MsgBox(48, "Meeeeeec", "You should select something.") Else _Renaming() EndIf Else MsgBox(48, "I'm sorry but...", "to do my job you should be on an Explorer window") EndIf EndFunc ;==>_Selecting Func _Renaming() Local $fTemp = "" For $i = 2 To UBound($aSelected) - 1 If StringRegExp($aSelected[$i], ".*wav$", 0) = 1 Then ;Check if file is wav $fTemp = StringRegExpReplace($aSelected[$i], "(?i)(.*)(\sv.*?)(\s.*)(\.wav)", "$1$3$2$4") If @error Then ContinueLoop FileCopy($aSelected[$i], $aSelected[$i] & ".original"); Create backup from original file before rename it FileMove($aSelected[$i], $fTemp); Renaming file EndIf Next EndFunc ;==>_Renaming Func _Exit() MsgBox(64, "Bye bye", "Exiting RenameSelected script", 4) Exit 0 EndFunc ;==>_Exit ; =================================================================================================================== ; Name...........: _WindowsExplorer_ExtractSelectedDirAndFiles ; Description....: Function to extract LocationURL and selected files from a "Windows Explorer" Window ; Syntax.........: _WindowsExplorer_ExtractSelectedDirAndFiles($hWnd) ; Parameters.....: $hWnd - Windows handle of an "Windows Explorer" Window ; AutoIt Version.: 3.3.6.1 ; Return values..: Success - Array ; Array[0] = Number of files selected in right-hand Listview ; Array[1] = LocationURL - selected in left-hand Treeview or Window Rebar ; Array[2] - Array[n] = URL of selected files in right-hand Listview ; Failure - Array ; Array[0] = 0 ; Array[1] = "" ; Sets the @error flag to non-zero. ; @error = 1 - $hwnd is not a valid window handle ; @error = 2 - $hwnd is not a window handle for an "Windows Explorer" Window ; @error = 3 - "Shell.Application" object could not be created ; @error = 4 - "$oShellApp.Windows()" object could not be created ; Author.........: Ascend4nt, KaFu, klaus.s ; =================================================================================================================== Func _WindowsExplorer_ExtractSelectedDirAndFiles($hWnd) Local $aExplorerSelectedFiles[2] = [0, ""] If Not IsHWnd($hWnd) Then Return SetError(1, 0, $aExplorerSelectedFiles) Local $aWinList = WinList("[REGEXPCLASS:(Explore|Cabinet)WClass]") While 1 For $i = 1 To UBound($aWinList) - 1 If $hWnd = $aWinList[$i][1] Then ExitLoop 2 Next Return SetError(2, 0, $aExplorerSelectedFiles) WEnd Local $oShellApp = ObjCreate("Shell.Application") If Not IsObj($oShellApp) Then Return SetError(3, 0, $aExplorerSelectedFiles) Local $oShellApp_Windows = $oShellApp.Windows() If Not IsObj($oShellApp_Windows) Then Return SetError(4, 0, $aExplorerSelectedFiles) For $oShellApp_Inst In $oShellApp_Windows If $oShellApp_Inst.hwnd = $hWnd Then ExitLoop Next Local $iShellApp_Inst_SelectedItems_Count = $oShellApp_Inst.document.SelectedItems.Count Local $sShellApp_Inst_LocationURL = $oShellApp_Inst.LocationURL Local $aRet = DllCall('shlwapi.dll', 'long', 'PathCreateFromUrlW', 'wstr', $sShellApp_Inst_LocationURL, 'wstr', '', 'dword*', 65534, 'dword', 0) If Not @error And $aRet[0] = 0 Then $sShellApp_Inst_LocationURL = $aRet[2] $aExplorerSelectedFiles[0] = $iShellApp_Inst_SelectedItems_Count $aExplorerSelectedFiles[1] = $sShellApp_Inst_LocationURL ReDim $aExplorerSelectedFiles[$aExplorerSelectedFiles[0] + 2] $oShellApp_Inst_SelectedItems = $oShellApp_Inst.document.SelectedItems Local $iCounter = 2 For $oShellApp_Inst_SelectedItem In $oShellApp_Inst_SelectedItems $aExplorerSelectedFiles[$iCounter] = $oShellApp_Inst_SelectedItem.path $iCounter += 1 Next $oShellApp = 0 $oShellApp_Windows = 0 $oShellApp_Inst = 0 $oShellApp_Inst_SelectedItems = 0 $oShellApp_Inst_SelectedItem = 0 Return $aExplorerSelectedFiles EndFunc ;==>_WindowsExplorer_ExtractSelectedDirAndFiles Cheers, sahsanu 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