Old post edition : I wanted a way to smartly extract archive based on their content. I managed to create a button here.
This (from the Scripts (JS & VBS) Snippet: Enumerating files and metadata tags sticky post) works with zip files and will normally use a cached directory listing if the zip is already open:
[code]function OnClick(clickData)
{
var folderEnum = DOpus.FSUtil.ReadDir(clickData.func.sourcetab.path, false);
while (!folderEnum.complete)
{
var folderItem = folderEnum.next;
if (folderItem.is_dir)
{
DOpus.Output("Dir: " + folderItem);
}
else
{
DOpus.Output("File: " + folderItem);
}
}
}[/code]
That should be all you need.
Thanks.
Currently my DOpus thanks to archive plugins allow me to read as folder more than zip files but also 7z, ARJ, BZip2, CAB, CB7, CBR, CBZ, Gzip, ISO, LZH, RAR, TAR. Does the snippet above could access those archives format or the most common of them?
It should do, and does with 7z at least, from a quick test here.
The best way to find out is to try it.
It should work with any archive you can read into Opus as a directory in the lister.
Yes, thank you. I just test it and it works as intended for zip, rar and 7z. Didn't test any other format but it should be ok.
First post updated with a rough JS template with lots of comments and questions in it?
I wish tbone and others will take a look and answer those questions. I'm novice in coding.
With the greatest of respect to tbone, most of your questions seem to be related to the various helpers that your script seems to be full of. If you really want to learn scripting I would start with the basics, using the examples in the Opus manual. tbone's classes add a lot of overhead and complexity and if you're still beginning they probably make things much harder to understand than they need to be.
Yes, directly using some of my helpers adds additional complexity, I must agree with Jon. On the other hand, you were able to put them to work without my assistence. XLog + ConfigHelper and the ArgsMagic parameter wrapper are in working condition, so congratulations! o)
If you got this far, I must assume you have some knowledge about scripting, since the really bloody beginner would have serious troubles to not mess things up with syntax errors while copying and glueing code together. I made some comments into your upload, maybe they help you understand. I see only small things that need clearance currently, so maybe we can get you going, even if you skipped the DO "basics" chapter.
If that fails, you really should build your first script addin from the ground up, not using any helpers and read some more docs. At least, leave out the ArgsMagic thing in the beginning. The ConfigHelper and XLog functionality are quite easy and do not add much noise, once you got to the core functionality of your script.
I also uncommented/readded the bad-params code-section at the bottom of "OnArchiveEx()", now your template is ready to be filled I guess.
Btw: Not using the helpers at first is the only way to understand why some of these helpers are there or why I/some tend to use them. o)
Smart Archive Management.js.txt (28.5 KB)
Thanks you both.
Of course I read the manual too, no can do without it. It was a big help to release my previous Button: Merge Folders v2 VBS script without asking anyone. But it was an enhancement of an existent script and VBS is intuitive and more human readable while JS need you to study its versatile syntax, anonymous function, object/class creation, etc. There resides its power.
Yes, tbone, I'm not a really bloody beginner but my JS skills have never got the opportunity to be used and exceed the basics to manipulate the DOM in the past, never had to build class, etc. I need to revise the basics and more. It's kind of exiting too although my brain is about to explode sometimes when I'm stuck with an error or an expected situation.
I'm gonna study your return and maybe let go ArgsMagic.
Thanks
Please don't do that as it makes question & answer threads very difficult to follow/understand/answer. It's exactly why editing is disabled in Help & Support.
(OTOH, it makes sense for download threads. And we allow editing in this part of the forum so people can correct typos in script code etc.)
I wrote some vbscript that does something similar to what the original poster was aiming for (it can be adapted to suit different preferences in terms of extraction behavior).
It works as follows:
Select one or more archive files and run the button command posted below. The archives will be extracted to the current source using the following behavior:
-
if any of the selected archives contains more than one item, its contents will be extracted to a folder with the same name as the archive. If there's already an existing folder with that name in the source, an incremental number will be appended, like "folder (1)".
-
if, however, any of the selected archives contains only one item, the content will be extracted directly to the source. If the source already contains a file or folder with the same name, the extracted item will be renamed by appending an incremental number, like "filename (1).ext" or "folder (1)".
The script should be copied and pasted into a context menu button under your "Archive" file type group (I'm assuming most people will have an "Archive" file type group). The button should be used in this way because the script does not check whether the selected files are archives - I let Opus do that by simply adding this button to the "Archives" file type group context menu.
Suggestions for improvement are welcome.
@script VBScript
Option Explicit
Dim cmd,src,selArchive,archiveItem,archiveEnum,index,targetFolder
Set cmd = DOpus.Create.Command
Set src = DOpus.listers.lastactive.activetab
For Each selArchive in src.selected
cmd.AddFile selArchive
cmd.RunCommand "GetSizes"
cmd.ClearFiles
Set archiveEnum = DOpus.FSUtil.ReadDir(selArchive, False)
If ((selArchive.metadata.other.filecount + selArchive.metadata.other.dircount) > 1) Then
If Not (DOpus.FSUtil.Exists(selArchive.path & "\" & selArchive.name_stem)) Then
cmd.RunCommand "CreateFolder " & """" & selArchive.name_stem & """" & " NOSEL"
targetFolder = selArchive.path & "\" & selArchive.name_stem
Else
Do
index = index + 1
If Not(DOpus.FSUtil.Exists(selArchive.path & "\" & selArchive.name_stem & " (" & index & ")")) Then
cmd.RunCommand "CreateFolder " & """" & selArchive.name_stem & " (" & index & ")" & """" & " NOSEL"
targetFolder = selArchive.path & "\" & selArchive.name_stem & " (" & index & ")"
index = 0
Exit Do
End If
Loop
End If
Do While (Not archiveEnum.complete)
Set archiveItem = archiveEnum.Next
cmd.AddLIne "Copy " & """" & archiveItem & """" & " TO " & """" & targetFolder & """"
Loop
cmd.Run
cmd.Clear
Else
Do While (Not archiveEnum.complete)
Set archiveItem = archiveEnum.Next
If (archiveItem.is_dir) Then
If (DOpus.FSUtil.Exists(selArchive.path & "\" & archiveItem.name)) Then
Do
index = index + 1
If Not(DOpus.FSUtil.Exists(selArchive.path & "\" & archiveItem.name & " (" & index & ")")) Then
cmd.AddLine "Copy " & """" & archiveItem & """" & " AS " & """" & archiveItem.name & " (" & index & ")" & """" & " TO {sourcepath$}"
index = 0
Exit Do
End If
Loop
Else
cmd.AddLine "Copy " & """" & archiveItem & """" & " TO {sourcepath$}"
End If
Else
cmd.AddLine "Copy " & """" & archiveItem & """" & " TO {sourcepath$} whenexists=rename"
End If
Loop
cmd.Run
cmd.Clear
End If
Next
Nice it works on Dopus 11.
You can create a button following theses steps, the button will run the smart extract script on selected items but only items that are actually archive will be affected:
- Add this filter : Non archive.zip (451 Bytes)
(extract the archive and copy the Non archive.ofi file in /dopusdata\Filters). It matches everything that is not an archive (used to deselect non archive files). - Restart Dopus after that.
- Download this button : Extract (smart).dcf (5.2 KB)
- Enter customize mode.
- Drag & drop Extract (smart).dcf in a toolbar.
You can customize the Non archive filter in Dopus preferences>file operations>filters. Feel free to add other needed and supported types.
The button auto deselect files that are not archive according to the filter before running the script.
@OpusFiend Feel free to add your solution and my button to a dedicated topic in #buttons-scripts section.
Update : I created a button for DOpus 12 that works perfectly. Check Smart archive extraction