ioa747 105 Posted March 11 Share Posted March 11 (edited) MoveTo.au3 Copy – Move folders or files according to its .extension, to the favorite folders by default it has 10 positions (favorite folders) But this can be changed via the ini file [Configuration] Elements=10 I have it compiled into an Exe file in the right click context menu for move or copy But I have also made a shortcut MoveTo Droper, which is very practical for Drag drop, which does not need to be compiled since it need a file parameter you can test it by dropping a file on the MoveTo Droper shortcut expandcollapse popup; https://www.autoitscript.com/forum/topic/209863-copy-move-folders-or-files-according-to-its-extension-to-the-favorite-folders/ ;------------------------------------------------------------------------------ ; Title...........: MoveTo.au3 ; Description.....: Copy – Move folders or files according to its .extension, to the favorite folders ;------------------------------------------------------------------------------ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $MyIni = @ScriptDir & "\MoveTo.ini" Global $HoldLogBook = True ; Read the INI file for the value of 'Elements' else 10 Global $iElements = IniRead($MyIni, "Configuration", "Elements", 10) Global $iStep = 20 #Region === GUI section === Global $MyGui = GUICreate("MoveTo....", 400, ($iElements * $iStep) + $iStep + 1, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) Global $MoveCheckbox = GUICtrlCreateCheckbox("Move", 2, 0, 46, 18) GUICtrlSetState($MoveCheckbox, $GUI_CHECKED) Global $idFileName = GUICtrlCreateLabel("FileName", 51, 0, 349, 18, $SS_CENTERIMAGE) Global $idMoveTo[$iElements + 1] Global $idPath[$iElements + 1] Global $idSetTo[$iElements + 1] $idMoveTo[0] = $iElements $idPath[0] = $iElements $idSetTo[0] = $iElements For $i = 1 To $iElements $idMoveTo[$i] = GUICtrlCreateButton("MoveTo", 1, $i * $iStep, 49, 20, $BS_VCENTER) GUICtrlSetTip(-1, $i) Next For $i = 1 To $iElements $idPath[$i] = GUICtrlCreateLabel("Path" & $i, 51, ($i * $iStep) + 1, 323, 18, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 10, 400, 0, "Arial Narrow") Next For $i = 1 To $iElements $idSetTo[$i] = GUICtrlCreateButton("...", 375, $i * $iStep, 24, 20, $BS_VCENTER) Next Global $Graphic1 = GUICtrlCreateGraphic(0, 0, 400, $iElements * $iStep) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xadadad) For $i = 1 To $iElements + 1 GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, 0, $i * $iStep) GUICtrlSetGraphic($Graphic1, $GUI_GR_LINE, 400, $i * $iStep) Next #EndRegion === GUI section === ; Make MoveTo.Droper.lnk Shortcut If Not FileExists(@ScriptDir & "\MoveTo.Droper.lnk") Then MakeExecuteShortcut(@ScriptFullPath) EndIf Global $sParams = $CmdLine[0] If Not $sParams Then MsgBox(4096, "INFORMATION", "This means that you have run the " & @CRLF _ & " --> " & @ScriptName & " <-- " & @CRLF & @CRLF _ & " without command line parameters." & @CRLF _ & " and for this reason is abording.") Exit Else $sParams = $CmdLine EndIf Global $mPos, $NewPath, $var, $ActiveFile, $OperationMode, $sFileExtension = "" $mPos = MouseGetPos() WinMove("MoveTo....", "", $mPos[0] - 60, $mPos[1] - 10) GUISetState(@SW_SHOW) For $i = 1 To $sParams[0] ConsoleWrite(@CRLF & "$sParams[$i]=" & $sParams[$i] & @CRLF) CheckFile($sParams[$i]) GUICtrlSetFont($idFileName, 13, 400, 0, "Arial Narrow") ReadIni() Sleep(100) GUICtrlSetFont($idFileName, 9, 400, 0, "Arial Narrow") MyProcess() WriteIni() Next GoToExit() ;---------------------------------------------------------------------------------------- Func GoToExit() ;~ WriteIni() Exit EndFunc ;==>GoToExit ;---------------------------------------------------------------------------------------- Func MyProcess() Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GoToExit() Case $MoveCheckbox If _IsChecked($MoveCheckbox) Then GUICtrlSetData($MoveCheckbox, "Move") WinSetTitle($MyGui, "", "MoveTo....") $OperationMode = "MoveTo" Else GUICtrlSetData($MoveCheckbox, "Copy") WinSetTitle($MyGui, "", "CopyTo....") $OperationMode = "CopyTo" EndIf For $i = 1 To $iElements GUICtrlSetData($idMoveTo[1] - 1 + $i, $OperationMode) Next ;==================== Move =============================== Case $idMoveTo[1] To $idMoveTo[1] + $iElements - 1 ConsoleWrite("$nMsg=" & $nMsg & @CRLF) $NewPath = GUICtrlRead($idPath[$nMsg - $idMoveTo[1] + 1]) MoveTo($NewPath) Return 1 ;===================== Set ============================== Case $idSetTo[1] To $idSetTo[1] + $iElements - 1 $mPos = MouseGetPos() GUISetState(@SW_HIDE) $var = FileSelectFolder("Choose a folder.", "", 1) GUISetState(@SW_SHOW) MouseMove($mPos[0] - 350, $mPos[1], 0) CheckVar($var) GUICtrlSetData($idPath[$nMsg - $idSetTo[1] + 1], $var) GUICtrlSetTip($idPath[$nMsg - $idSetTo[1] + 1], $var) EndSwitch WEnd EndFunc ;==>MyProcess ;---------------------------------------------------------------------------------------- Func CheckVar(ByRef $var) If StringLen($var) = 0 Then $var = @MyDocumentsDir EndIf EndFunc ;==>CheckVar ;---------------------------------------------------------------------------------------- Func ReadIni() Local $Data, $Section ; Read the INI section names. This will return a 1 dimensional array. Local $aArray = IniReadSectionNames($MyIni) ; Check if an error occurred. If Not @error Then ; Enumerate through the array to the section names. For $i = 1 To $aArray[0] If $sFileExtension = $aArray[$i] Then $Section = $aArray[$i] ExitLoop EndIf Next EndIf ; Enumerate through the array set the keys and their values. For $i = 1 To $iElements $Data = IniRead($MyIni, $Section, "Path" & $i, @MyDocumentsDir) GUICtrlSetData($idPath[1] - 1 + $i, $Data) GUICtrlSetTip($idPath[1] - 1 + $i, $Data) Next EndFunc ;==>ReadIni ;---------------------------------------------------------------------------------------- Func WriteIni() Local $Data IniWrite($MyIni, "Configuration", "Elements", $iElements) For $i = 1 To $iElements $Data = GUICtrlRead($idPath[1] - 1 + $i) IniWrite($MyIni, $sFileExtension, "Path" & $i, $Data) Next EndFunc ;==>WriteIni ;---------------------------------------------------------------------------------------- Func CheckFile($FilePath) Local $attrib = FileGetAttrib($FilePath) If @error Then MsgBox(4096, "Error", "Could not obtain attributes from" & @CRLF & $FilePath) PutInLogg("!!! ReadFile --> Error Could not obtain attributes from " & $FilePath) Exit Else If StringInStr($attrib, "D") Then $sFileExtension = "Folder" Else $sFileExtension = FileExt($FilePath, "Ext") EndIf $ActiveFile = $FilePath GUICtrlSetData($idFileName, $ActiveFile) GUICtrlSetTip($idFileName, $ActiveFile) EndIf EndFunc ;==>CheckFile ;---------------------------------------------------------------------------------------- Func FileExt($MyPath, $Part) ;where 0 = original path, 1 = drive, 2 = directory, 3 = filename, 4 = extension Local $szDrive, $szDir, $szFName, $szExt _PathSplit($MyPath, $szDrive, $szDir, $szFName, $szExt) Switch $Part Case 1, "Drive" Return $szDrive Case 2, "Dir" Return $szDir Case 3, "FName" Return $szFName Case 4, "Ext" Return $szExt Case Else Return $MyPath EndSwitch EndFunc ;==>FileExt ;---------------------------------------------------------------------------------------- Func MoveTo($destination) Local $NewFile, $result $NewFile = $ActiveFile If $sFileExtension = "Folder" Then ;MsgBox(4096, "", "is Dir") $result = StringInStr($NewFile, "\", 0, -1) $NewFile = StringTrimLeft($NewFile, $result) If GUICtrlRead($MoveCheckbox) = $GUI_UNCHECKED Then DirCopy($ActiveFile, $destination & "\" & $NewFile) PutInLogg("DirCopy " & $ActiveFile & " --> " & $destination & "\" & $NewFile) Else DirMove($ActiveFile, $destination & "\" & $NewFile) PutInLogg("DirMove " & $ActiveFile & " --> " & $destination & "\" & $NewFile) EndIf Else $result = StringInStr($NewFile, "\", 0, -1) $NewFile = StringTrimLeft($NewFile, $result) If GUICtrlRead($MoveCheckbox) = $GUI_UNCHECKED Then FileCopy($ActiveFile, $destination & "\" & $NewFile) PutInLogg("FileCopy " & $ActiveFile & " --> " & $destination) Else FileMove($ActiveFile, $destination & "\" & $NewFile) PutInLogg("FileMove " & $ActiveFile & " --> " & $destination) EndIf EndIf Return $destination & "\" & $NewFile EndFunc ;==>MoveTo ;---------------------------------------------------------------------------------------- Func PutInLogg($TxtData) If $HoldLogBook = False Then Return Local $LogName = FileExt(@ScriptFullPath, "FName") _FileWriteLog(@ScriptDir & "\" & $LogName & ".log", $TxtData) EndFunc ;==>PutInLogg ;---------------------------------------------------------------------------------------- Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked ;---------------------------------------------------------------------------------------- Func MakeExecuteShortcut($au3Path, $PreFix = "") ; Make .Droper.lnk Shortcut Local $sDrive, $sDir, $sFileName, $sExtension _PathSplit($au3Path, $sDrive, $sDir, $sFileName, $sExtension) ;where 0=original path, 1=drive, 2=directory, 3=filename, 4=extension ; Create a constant variable in Local scope of the shortcut filepath. Local Const $sortFilePath = $sDrive & $sDir & $PreFix & $sFileName & " Droper.lnk" ; Create a shortcut FileCreateShortcut("C:\Program Files (x86)\AutoIt3\AutoIt3.exe", _ ;file $sortFilePath, _ ;lnk $sDrive & $sDir, _ ;workdir " /AutoIt3ExecuteScript " & $sDrive & $sDir & $sFileName & $sExtension, _ ;args "Drop file or folder here to move or copy", _ ;desc "mmcndmgr.dll", "", 31) ;icon EndFunc ;==>MakeExecuteShortcut ;---------------------------------------------------------------------------------------- For anything, suggestions, comments, please post it to the thread thank you very much Edited March 11 by ioa747 Link to post Share on other sites
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