I have a problem. I need a way to zip selected files into a zipped folder located in the current directory. The current approach does work, but it is a) slow, and b) reliant on the existence of 7-zip on the PC. The first problem I suspect is just due to the number of files I tend to zip isn't exactly low, and I can live with that. The second problem is okay as long as I can work on my own machine, where I can ensure 7zip exists.
I suspect there are native ways to do this, but I don't have any idea as to how I'd do this :/
Thank you.
Sincerely,
~Gw
Note on fClip:
fClip is just a much more reliable way of using the clipboard, and in this case, effectively only copies the selected file paths onto the clipboard, and then outputs them to this variable, reverting the last clipboard change. For this case, it is synonymous with pressing Ctrl+C before running this code without this step, with the exception that I would lose the original clipboard. The code is below. Works 95% of the time for me.
Code: Select all
#z:: ; FileZipper || Zip Selected Files into directory
gui_control_options := "xm w220 " . cForeground . " -E0x200" ; remove border around edit field
Gui, Margin, 16, 16
Gui, +AlwaysOnTop -SysMenu -ToolWindow -caption +Border
cBackground := "c" . "1d1f21"
cCurrentLine := "c" . "282a2e"
cSelection := "c" . "373b41"
cForeground := "c" . "c5c8c6"
cComment := "c" . "969896"
cRed := "c" . "cc6666"
cOrange := "c" . "de935f"
cYellow := "c" . "f0c674"
cGreen := "c" . "b5bd68"
cAqua := "c" . "8abeb7"
cBlue := "c" . "81a2be"
cPurple := "c" . "b294bb"
Gui, Color, 1d1f21, 373b41,
Gui, Font, s11 cWhite, Segoe UI
;Gui, Font, s11 cComment, Segoe UI
gui, add, text,xm ym, Enter Name of zipped directory
Gui, add, Edit, %gui_control_options% -VScroll vfileName
Gui, add, Button, default gSubmitFileZipper h0 w0 xs-50 ys -50
Hotkey, Esc, gui_destroy_FileZipper, On ; Escape Key FileZipper-Gui
gui, show,, FileZipper
return
gui_destroy_FileZipper:
Hotkey, Esc, gui_destroy_FileZipper, Off ; Escape Key FileZipper-Gui
gui, destroy
return
SubmitFileZipper:
gui, submit
gui, destroy
Store:=ClipboardAll
fileList := ""
FilesToZip:=fClip() ;; fClip is just a much more reliable way of using the clipboard, and in this case effectively only copies the selected file paths onto the clipboard, and then outputs them to this variable, reverting the last clipboard change . It is synonymous to pressing Ctrl+C before running this code without this step, with the exception that I would loose the original clipboard.
sevenZip := A_ProgramFiles "\7-zip\7z.exe"
loop parse, % RTrim(FilesToZip, "`r`n"), `n, `r
fileList .= " " quote(dir := A_LoopField)
SplitPath dir,, dir
fileList := StrReplace(fileList, dir "\")
Run % sevenZip " a -tzip " quote(fileName ".zip") fileList, % dir
WinWaitActive ahk_exe 7z.exe
WinMinimize
Clipboard:=Store
return
quote(str)
{
return """" str """"
}
return
Code: Select all
; Clip() - Send and Retrieve Text Using the Clipboard
; by berban - updated February 18, 2019
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156
; adapted by Gewerd Strauss
fClip(Text="", Reselect="")
{
;MsgBox, %A_ThisLabel%`n%A_ThisFunc%
; msgbox, Text imported:`n|%Text%|
if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos.
{
move := StrLen(Text) - RegExMatch(Text, "[&|]")
Text := RegExReplace(Text, "[&|]")
sleep, 20
MoveCursor=true
}
Static BackUpClip, Stored, LastClip
If (A_ThisLabel = A_ThisFunc)
{
If (Clipboard == LastClip)
Clipboard := BackUpClip
BackUpClip := LastClip := Stored := ""
}
Else
{
If !Stored
{
Stored := True
BackUpClip := ClipboardAll ; ClipboardAll must be on its own line
}
Else
SetTimer, %A_ThisFunc%, Off
LongCopy := A_TickCount, Clipboard := "", LongCopy -= A_TickCount ; LongCopy gauges the amount of time it takes to empty the clipboard which can predict how long the subsequent clipwait will need
If (Text = "")
{
SendInput, ^c
ClipWait, LongCopy ? 0.6 : 0.2, True
}
Else
{
Clipboard := LastClip := Text
ClipWait, 10
SendInput, ^v
;msgbox, fclip:`n %Clipboard%
if MoveCursor
{
/*
Date: 04 April 2021 17:59:25:
stupid hotfix for uni mail below, because the
parsing doesn't work if there is NO MSGBOX in this
code. WTF
*/
if WinActive("E-Mail – [email protected] - Google Chrome")
{
WinActivate
MsgBox, %A_Space%,BS-msgbox
sleep, 20
WinActivate, "E-Mail – [email protected] - Google Chrome"
WinClose, BS-msgbox-msgbox
SendInput, % "{Left " move-1 "}"
}
else
SendInput, % "{Left " move-1 "}"
}
}
SetTimer, %A_ThisFunc%, -700
Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter}
If (Text = "")
{
SetTimer, %A_ThisFunc%, Off
Return LastClip := Clipboard
}
Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000))
{
SetTimer, %A_ThisFunc%, Off
SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}"
}
}
SendInput, {Ctrl Up}
SendInput, {V Up}
SendInput, {Shift Up}
Return
fClip:
Return fClip()
}