AutoHotkey - 作为路径的一部分调用的 Zip
AutoHotkey - Zip called as a part of a path
1. 我在一个名为“2”的特定文件夹中,其中有不同类型的文件,路径如下所示:
"C:\Users\Me\Desktop\Named_Folder"
我想将所有这些文件放在一个 Zip 中,脚本应该是什么样子,最后 Zip 将被称为 "Named_Folder",与路径中的文件夹相同?需要提到的是 "Named_Folder" 每次都会有不同的名称。那么如何将zip命名为上面的两个目录呢
2. 到现在为止我刚刚找到了将所有这些文件放在一个 zip 中的脚本:
#IfWinActive ahk_class CabinetWClass
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
return
以及结合 1. 和 2. 步骤的脚本应该是什么样子?用一个字母的快捷键。
所以最后的结果应该是这样的:
3. 然后我想将下面的两个脚本(F2 F3 或什至 F1 如果它改变任何东西)与一个字母快捷方式(4 个第一行来自默认 AHK文件):
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#If WinActive("ahk_class CabinetWClass") ; explorer
F1::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
; IfExist, %Fullpath%\
Run, %Fullpath%
return
F2::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
; IfExist, %Fullpath%\
Run, %Fullpath%
return
#If
#IfWinActive ahk_class CabinetWClass
F3::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
if (SubStr(Fullpath, -3) = "")
{
StringReplace, Fullpath, Fullpath, :,
StringTrimRight, Fullpath, Fullpath, 4
StringSplit, folder_array, Fullpath, \,
MsgBox, % folder_array%folder_array0%
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
}
return
#IfWinActive
4. 然后解压zip(右击-->上下文菜单-->解压到"folder with the same name as zip"
因此它会创建一个名为 "NAMED_FOLDER" 的文件夹,其中包含所有提取的内容。
我知道当我 select 压缩并按下鼠标右键(打开上下文菜单)并按下字母 "e" 时它会起作用。
5. 然后将这个 Zip 和这个新解压的文件夹移动到桌面文件夹 "FINAL"
最后用一个字母的快捷方式完成所有这 5 个步骤。这会对我产生一些我真正需要的工作流程的巫毒魔法。
#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
}
return
或者这个:
#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
FileCreateDir %A_Desktop%\FINAL
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
Sleep 2000 ; wait 2 seconds
SetTimer, CopyDir, 500
}
return
CopyDir:
IfExist, %Fullpath%\%FolderName%.zip
return
SetTimer, CopyDir, off
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
return
1. 我在一个名为“2”的特定文件夹中,其中有不同类型的文件,路径如下所示:
"C:\Users\Me\Desktop\Named_Folder"
我想将所有这些文件放在一个 Zip 中,脚本应该是什么样子,最后 Zip 将被称为 "Named_Folder",与路径中的文件夹相同?需要提到的是 "Named_Folder" 每次都会有不同的名称。那么如何将zip命名为上面的两个目录呢
2. 到现在为止我刚刚找到了将所有这些文件放在一个 zip 中的脚本:
#IfWinActive ahk_class CabinetWClass
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
return
以及结合 1. 和 2. 步骤的脚本应该是什么样子?用一个字母的快捷键。
所以最后的结果应该是这样的:
3. 然后我想将下面的两个脚本(F2 F3 或什至 F1 如果它改变任何东西)与一个字母快捷方式(4 个第一行来自默认 AHK文件):
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#If WinActive("ahk_class CabinetWClass") ; explorer
F1::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
; IfExist, %Fullpath%\
Run, %Fullpath%
return
F2::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
; IfExist, %Fullpath%\
Run, %Fullpath%
return
#If
#IfWinActive ahk_class CabinetWClass
F3::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
if (SubStr(Fullpath, -3) = "")
{
StringReplace, Fullpath, Fullpath, :,
StringTrimRight, Fullpath, Fullpath, 4
StringSplit, folder_array, Fullpath, \,
MsgBox, % folder_array%folder_array0%
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
}
return
#IfWinActive
4. 然后解压zip(右击-->上下文菜单-->解压到"folder with the same name as zip"
因此它会创建一个名为 "NAMED_FOLDER" 的文件夹,其中包含所有提取的内容。 我知道当我 select 压缩并按下鼠标右键(打开上下文菜单)并按下字母 "e" 时它会起作用。
5. 然后将这个 Zip 和这个新解压的文件夹移动到桌面文件夹 "FINAL"
最后用一个字母的快捷方式完成所有这 5 个步骤。这会对我产生一些我真正需要的工作流程的巫毒魔法。
#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
}
return
或者这个:
#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
FileCreateDir %A_Desktop%\FINAL
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
Sleep 2000 ; wait 2 seconds
SetTimer, CopyDir, 500
}
return
CopyDir:
IfExist, %Fullpath%\%FolderName%.zip
return
SetTimer, CopyDir, off
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
return