Skip to content

Instantly share code, notes, and snippets.

@TaranVH
Created September 19, 2016 22:20
Show Gist options
  • Save TaranVH/19dc6552cb9968abc2d0ad14d359c376 to your computer and use it in GitHub Desktop.
Save TaranVH/19dc6552cb9968abc2d0ad14d359c376 to your computer and use it in GitHub Desktop.
moves files to a folder, unless they are already in that folder tree. Doesn't quite work yet unless you copy the file manually...????
debug:
tooltip, counter = %counter%`nnlines = %nlines%, , , 9
return
;;;;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\"
FileMover(publishLOC) {
msgbox, you want %publishLOC%
tooltip, F10, , , 3
Send, ^c
sleep 10
filetomovePATH =
SlashPosition = 0
file2move =
Files =
existinglocation = ;if you don't refresh these variables, they will retain data from previous run-throughs.
FileListLocations =
Fileposition =
Loop, parse, clipboard, `n, `r
{
filetomovePATH = %A_LoopField%
; MsgBox, 4, , File number %A_Index% is named %A_LoopField%.`n`nContinue?
; IfMsgBox, No, break
msgbox, the current file pathh is `n%filetomovePATH%
SlashPosition := InStr(filetomovePATH, "\" ,false,-1,1) ;first occurance from the right to the left, supposedly.
; lenn := % Strlen(file2move)
; msgbox, length = %lenn%
; msgbox, slash is at: %slashposition%
; lols := lenn - SlashPosition + 0
; msgbox, lols = %lols%
StringTrimLeft,file2move,filetomovePATH, %slashposition%
msgbox, file2move = `n%file2move%
break
}
;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
counter = 0
nlines = 0
settimer debug, 20
msgbox, launching debugger
sleep 20
Loop Parse, FileList, `n
++nlines
MsgBox, total lines here, or nlines: %nlines%
Loop, parse, FileList, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list.
continue
If A_LoopField = %file2move%
{
Fileposition = %A_Index%
Loop, parse, FileListLocations, `n
if A_index = %Fileposition%
existinglocation = %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, existinglocation = %existinglocation%
;A match has been found in this folder system, meaning the file was ALREADY moved over here before!
msgbox, 1, ,The file %A_LoopField% is already present at`n%existinglocation%`n...Want to see?
IfMsgBox, OK
{
;Run, explore, % existinglocation ;<---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`, "%existinglocation%",, 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 = nlines
break
;tooltip, count: %counter%, , ,5
}
msgbox, 1 , ,file %filetomovePATH% is NOT already present. Want to move it to %publishLOC% ?
IfMsgBox, OK
{
FileMove,%filetomovePATH%,%publishLOC%
Msgbox, did that work?
}
theEnd:
tooltip, you are at the end
sleep 100
tooltip, , , , 3
tooltip,
}
;end of file mover.
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment