Skip to content

Instantly share code, notes, and snippets.

@TaranVH
Created September 21, 2016 01:50
Show Gist options
  • Save TaranVH/f92b0010645d9683b68ce0e564c3b539 to your computer and use it in GitHub Desktop.
Save TaranVH/f92b0010645d9683b68ce0e564c3b539 to your computer and use it in GitHub Desktop.
This will move a file to a folder, UNLESS that file is already in the folder, or in one of the folders above.
;;;;FILE MOVER TO TRANSCODE FOLDERS
; YTpublish = "Z:\Linus\1. Linus Tech Tips\Transcode\YT Publish 4K\"
; VESpublish = "Z:\Linus\1. Linus Tech Tips\Transcode\Vessel Final 4K\"
Explorer_GetSelection(hwnd="") {
;msgbox, now in getselection
hwnd := hwnd ? hwnd : WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (class="CabinetWClass" or class="ExploreWClass" or class="Progman")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
;msgbox, %ToReturn% is toreturn
return Trim(ToReturn,"`n")
}
filetomovePATH =
SlashPosition = 0
file2move =
filetomovePATH =
FileListLocations =
Fileposition =
counter = 0
nlines = 0
;BEGIN FUNCTION DEFINITION:
FileMover(publishLOC) {
filetomovePATH := Explorer_GetSelection() ;NOTE: does not work from the desktop for some stupid reason...
;;msgbox, you want to move this file to`n%publishLOC%
tooltip, Filemover Activated, , , 3
;Send, ^c
sleep 10
existingfile =
SlashPosition = 0
file2move =
filetomovePATH = ;if you don't refresh these variables, they will retain data from previous run-throughs.
FileListLocations =
Fileposition =
FileNotPresent = 0
filetomovePATH := Explorer_GetSelection()
;msgbox, the current file path is `n%filetomovePATH%
SlashPosition := InStr(filetomovePATH, "\" ,false,-1,1) ;first occurance from the right to the left, supposedly.
StringTrimLeft,file2move,filetomovePATH, %slashposition%
;;msgbox, file2move = `n%file2move% `n`nfiletomovePATH =`n%filetomovePATH%
;https://www.autohotkey.com/docs/commands/LoopFile.htm the following code does work to list files in a given directory!
FileList = ; Initialize to be blank.
Loop, Files, %publishLOC%*.*, DFR
FileList = %FileList%%A_LoopFileName%`n
Loop, Files, %publishLOC%*.*, DFR
FileListLocations = %FileListLocations%%A_LoopFileFullPath%`n ;A_LoopFileDir -or- A_LoopFileFullPath
;;msgbox, FileListLocations = `n%FileListLocations%
;;msgbox, FileList = `n%FileList%
counter = 0
nlines = 0
;settimer debug2, 20
;msgbox, launching debugger
sleep 20
Loop Parse, FileList, `n
++nlines
;;MsgBox, total lines here, or nlines: %nlines%
Loop, parse, FileList, `n
{
; tooltip, counter = %counter%`nnlines = %nlines%, , , 10
if A_LoopField = ; Ignore the blank item at the end of the list.
continue
;MsgBox, 4,, File number %A_Index% is %A_LoopField%. Continue?
;IfMsgBox, No
; break
If A_LoopField = %file2move%
{
Fileposition = %A_Index%
Loop, parse, FileListLocations, `n
if A_index = %Fileposition%
existingfile = %A_LoopField% ;I have to confess, I wrote those 4 lines all at once and i have no idea how they work... they just do.
;;msgbox, existingfile = %existingfile%
;A match has been found in this folder system, meaning the file was ALREADY moved over here before!
msgbox, 1, ,%A_LoopField%`nis already present at`n%existingfile%`n...Want to see?
IfMsgBox, OK
{
;Run, explore, % filetomovePATH ;<---this will only go to the folder, but WON'T highlight the file - it will just open it instead, unless you use A_LoopFileDir.
Run %COMSPEC% /c explorer.exe /select`, "%existingfile%",, Hide
;Run %COMSPEC% /c explorer.exe /select`, "%FileListLocations%",, Hide
;Msgbox, you win! File SHOULD be there already!
Goto, theEnd
}
IfMsgBox, Cancel
Goto, theEnd
}
;Msgbox, WHERE AM I
; MsgBox, 4,, File number %A_Index% is: `n%A_LoopField%`n`n...continue?
; IfMsgBox, No
; break
counter ++
if counter + 1 = nlines
{
;;msgbox, looked at all files, didn't find the one you are looking for. time to break.
FileNotPresent = 1
break
}
;tooltip, count: %counter%, , ,5
}
;;msgbox, end of the loop
if FileNotPresent = 1
{
msgbox, 1 , ,%filetomovePATH%`nis NOT present at or above `n%publishLOC%`n...would you like to move it there?
IfMsgBox, OK
{
FileCopy,%filetomovePATH%,%publishLOC%
Run %COMSPEC% /c explorer.exe /select`, "%publishLOC%%file2move%",, Hide
;;Msgbox, did that work?
FileNotPresent = 0
}
}
Goto, theEnd
theEnd:
;SetTimer, tooltipper, off
sleep 10
; tooltip, , , , 9
tooltip, , , , 3
; tooltip,
;;msgbox, you are at the VERY end
}
;end of file mover.
#IfWinActive
#IfWinActive ahk_exe explorer.exe
^F11::Filemover("Z:\Linus\1. Linus Tech Tips\Transcode\Vessel Final 4K\")
^F12::Filemover("Z:\Linus\1. Linus Tech Tips\Transcode\YT Publish 4K\")
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment