DonationCoder.com Software > Post New Requests Here
Request: Ahk script to extract archive to subfolder of current directory
4wd:
Since the ultimate point is to extract the contents of the archive I see no need to get the list of its contents before doing so, it adds unnecessary steps.
Only needed to find out if there was more than one object in the root of the archive.
If, after extraction, there was an already existing object of the same name then you can either rename, replace, or skip (and leave the extracted files in the temporary folder for comparison with the existing), which can be handled by a requester or a preset.
Like I said, there was no error checking in my script since it was just a sample of how easy it is to do.
Plus there was the reference to TC so the ultimate environment in which the script/program would be used was unknown.
chashnniel:
i found another solution(maybe)
this AHK script 智能解压
seems can do it.
But it is just a plugin, the author said it can be used as a independent script if i modify it. since i don't know how to code, anyone can help?
@KodeZwerg How about add a content menu if it is hard to get the Archive filename through a hotket+click?
Nod5:
Hi all. Here is an AutoHotkey prototype. I don't have time to make more of it right now. But maybe someone else takes this to the next level?
--- Code: Autohotkey ---;Smarter unzip sketch;by nod5 181114 ;note: only a sketch/prototype so far;todo: ;- add error checks/handling: ; 1 unzip errors (paths to long, or whatever); 2 file/folder move errors: ; - script currently silently avoids overwrite; - need to add code to prompt user: overwrite yes/no? and react accordingly;- must test how reliable the unzip function performs if the zip file is huge, etcetera;- notify user while processing (window, tooltip, etcetera);- prevent repeat commands while processing;- replace crude F5 refresh with something better, maybe also reselect zip file after refresh #IfWinActive ahk_exe explorer.exe!#Lbutton:: ;get first file in Explorer selection and verify that it is .zipclip := ClipToVar()Loop, parse, clip, `n, `r{ firstfile := A_LoopField break}if !FileExist(firstfile) or (SubStr(firstfile,-3) != ".zip") return ;unzip to temporary folderSplitPath, firstfile, , folder, , zipname_noexttempfolder := folder "\temp_" A_NowFileCreateDir, % tempfolder Unzip(firstfile, tempfolder) ;count unzipped files/folders recursivelyLoop, Files, % tempfolder "\*.*", FDR{ allcount := A_Index onlyitem := A_LoopFilePath} ;count unzipped files/folders at first level onlyLoop, Files, % tempfolder "\*.*", FD{ firstlevelcount := A_Index firstlevelitem := A_LoopFilePath} ;case1: only one file/folder in whole zipif (allcount = 1){ if InStr( FileExist(onlyitem), "D") { SplitPath, onlyitem, onlyfoldername FileMoveDir, % onlyitem, % folder "\" onlyfoldername } else FileMove , % onlyitem, % folder} ;case2: only one folder (and no files) at the first level in zipelse if (firstlevelcount = 1) and InStr(FileExist(firstlevelitem), "D"){ SplitPath, firstlevelitem, firstlevelfoldername FileMoveDir, % firstlevelitem, % folder "\" firstlevelfoldername} ;case3: multiple files/folders at the first level in zipelse{ FileMoveDir % tempfolder, % folder "\" zipname_noext} ;cleanup temp folderFileRemoveDir, % tempfolder, 1 ;refresh Explorer to show resultsIf WinActive("ahk_exe Explorer.exe") Send {F5}return ;function: copy selection to clipboard to varClipToVar() { cliptemp := clipboardall ;backup clipboard = send ^c clipwait, 1 clip := clipboard clipboard := cliptemp ;restore return clip} ;function: unzip files to already existing folder;zip file can have subfoldersUnzip(zipfile, folder){ psh := ComObjCreate("Shell.Application") psh.Namespace(folder).CopyHere( psh.Namespace(zipfile).items, 4|16)}
chashnniel:
@Nod5 thx!!! what a decent script!
i just test it, it works like a charm :Thmbsup: :Thmbsup:
a little suggestion(since it is just a prototype), it overwrites(my mistake, it just skip the same file) the files by default if it is already existed in the current folder. maybe you can add a overwrite confirm dialog.
Nod5:
it overwrites the files by default if it is already existed in the current folder
-chashnniel (November 14, 2018, 09:42 AM)
--- End quote ---
I don't think it does, on the contrary in my (quick) tests it silently skips to unzip/move files if another file with the same name exists in the target path. But yes, a complete program should handle such cases by asking the user what to do. However that would take more time, which I don't have for this right now. But someone else might.
Navigation
[0] Message Index
[*] Previous page
Go to full version