Jump to content

A few question and one problem with 7z UDF [SOLVED BEAUTIFULLY]


 Share

Recommended Posts

Hi there,

First of all i'm using rasim's 7z udf on my script. is it outdated. or are there any problems any "better" versions out there?

Also does 7z required to be installed on the users computer? I already tried to cut/ paste my 7-zip folder from program files folder and it DOES work. but i would like to be sure.

So if my questions are all right here is my problem with it;

I saw that 7zip udf has an exclude function built in. with a variable.

It works like this;

$exc = "*.mp3"
$retResult = _7ZipAdd($hGUI, $ArcFile, $sFolder, 1,0,1,0,$exc,$pass)
_7ZipShutdown()

But lets say i want to exclude all mp3 AND avi files. what should i do? i tried so far;

$exc = "*.mp3;*.avi"
$exc = "*.mp3, *.avi"

and none of them worked.

Edited by continyu
Link to comment
Share on other sites

does 7z required to be on the users computer?

it requires the DLL which is registered through Installation

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

furthermore i feel its better to ask the queries and questions in the topic itself

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

furthermore i feel its better to ask the queries and questions in the topic itself

Well i thought about that, but everyone was saying that rasim (creator of udf) has lost interest, so i think it's better to have my own topic. But if it's against any rule i will happily close this topic and move on with udf's topic :)

it requires the DLL which is registered through Installation

So if i include the DLL's which came with the udf i'm fine on every computer? Edited by continyu
Link to comment
Share on other sites

Good evening.

According to the documentation of 7Zip, although it is possible to use multiple exclude switches, but this was not yet implemented in the UDF. It is possible to make modification in the UDF, but for instance it's more simple to use @fileset with a filelist of what you want to exclude instead of wildcard.

From 7zip documentation :

List file

You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).

For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using <a href="switches/charset.htm">-scs switch.

Multiple list files are supported.

For example, if the file "listfile.txt" contains the following:

My programs*.cpp

Src*.cpp

then the command

7z a -tzip archive.zip @listfile.txt

adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".

Edited by Tlem

Best Regards.Thierry

Link to comment
Share on other sites

Would this

$exc = '*.mp3'&'*.avi'&'*.jpg'

Work?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Would this

$exc = '*.mp3'&'*.avi'&'*.jpg'

Work?

No luck sadly...

Good evening.

According to the documentation of 7Zip, although it is possible to use multiple exclude switches, but this was not yet implemented in the UDF. It is possible to make modification in the UDF, but for instance it's more simple to use @fileset with a filelist of what you want to exclude instead of wildcard.

From 7zip documentation :

if i get it right you are suggesting that i should use the "include" function somehow instead of "exclude" with this filelist system. if so, is that built in with rasim's udf?
Link to comment
Share on other sites

  • Moderators

Sometimes things come to life if you dissect the function you're utilizing, then follow it to the functions that it utilizes until you find the function that does what it is you're looking for.

In this case, ( no idea if it works ), I'd assume by following my own logic, that their is no set option provided to do more than 1 switch to exclude.

So maybe make your own sub function from the add function:

Func __7ZipAddEx($hWnd, $sArcName, $sFileName, $sHide = 0, $sCompress = 5, $sRecurse = 1, $sIncludeFile = 0, $sExcludeFile = 0, _
              $sPassword = 0, $sSFX = 0, $sVolume = 0, $sWorkDir = 0)

    $sArcName = '"' & $sArcName & '"'
    $sFileName = '"' & $sFileName & '"'
    
    Local $iSwitch = ""
    
    If $sHide Then $iSwitch &= " -hide"
    
    $iSwitch &= " -mx" & $sCompress
    $iSwitch &= _RecursionSet($sRecurse)
    
    ; ## change made here to allow multiple switches for exclude and include
    Local $a_switch = 0
    If $sIncludeFile Then
        $a_switch = StringSplit($sIncludeFile, ";", 2)
        For $i = 0 To UBound($a_switch) - 1
            $iSwitch &= _IncludeFileSet($a_switch[$i])
        Next
    EndIf
    If $sExcludeFile Then
        $a_switch = StringSplit($sExcludeFile, ";", 2)
        For $i = 0 To UBound($a_switch) - 1
            $iSwitch &= _ExcludeFileSet($a_switch[$i])
        Next
    EndIf
    
    If $sPassword Then $iSwitch &= " -p" & $sPassword
    
    If FileExists($sSFX) Then $iSwitch &= " -sfx" & $sSFX
    
    If $sVolume Then $iSwitch &= " -v" & $sVolume
    
    If $sWorkDir Then $iSwitch &= " -w" & $sWorkDir
    
    Local $tOutBuffer = DllStructCreate("char[32768]")
    
    Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZip", _
                                             "hwnd", $hWnd, _
                                             "str", "a " & $sArcName & " " & $sFileName & " " & $iSwitch, _
                                             "ptr", DllStructGetPtr($tOutBuffer), _
                                             "int", DllStructGetSize($tOutBuffer))
    
    If Not $aRet[0] Then Return SetError(0, 0, DllStructGetData($tOutBuffer, 1))
    Return SetError(1, 0, 0)
EndFunc

Try using that func instead of the main _7zipAdd() func.

And for exclude separate by semi colons like you tried before.

FYI Edit:

It would probably be smarter to just edit the _Include/_Exclude(fileset) functions directly rather than mess with each function ;)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@SmOke_N

I work on it. It's ok for _ExcludeFileSet.

For excluding files, we must give the parameters like this -x!*.mp3 -x!*.avi

We can easily modify _ExcludeFileSet and _ExcludeArcSet function to do it.

Func _ExcludeFileSet($sVal)
If StringInStr($sVal, ";") Then
Local $aVal = StringSplit($sVal, ";")
$sVal = ""
For $i = 1 to UBound($aVal) - 1
$sVal &= ' -x!"' & $aVal[$i] & '"'
Next
Return $sVal
ElseIf StringInStr($sVal, "*") Then
Return ' -x!"' & $sVal & '"'
ElseIf StringLeft($sVal, 1) = "@" Then
Return ' -x"' & $sVal & '"'
Else
Return ' -x!"' & $sVal & '"'
EndIf
EndFunc ;==>_ExcludeFileSet

But for including files, it's not so easy, If I do the same thing for _IncludeFileSet, the result is really surprising !!!

So actually I search what syntax to use, but I think that we must include the path (not sure). ^^

-i!$SearchPath*.mp3 -i!$SearchPath*.avi instead of -i!*.mp3 -i!*.avi

I will make search later on the journey.

Edit : After some testing, it seems that if you want to include multiple files, you must specify the path.

Also, I have made try with fileset, and it's the same problem.

If I use -i!*.mp3 -i!*.avi, the first parameter consider the search path, but not the second parameter!

Perhaps it's due to this dll ! In original documentation, we can read that multiple include switches are supported, but they don't explain how it must be used in multiple include...

Edited by Tlem

Best Regards.Thierry

Link to comment
Share on other sites

Sometimes things come to life if you dissect the function you're utilizing, then follow it to the functions that it utilizes until you find the function that does what it is you're looking for.

In this case, ( no idea if it works ), I'd assume by following my own logic, that their is no set option provided to do more than 1 switch to exclude.

So maybe make your own sub function from the add function:

Try using that func instead of the main _7zipAdd() func.

And for exclude separate by semi colons like you tried before.

FYI Edit:

It would probably be smarter to just edit the _Include/_Exclude(fileset) functions directly rather than mess with each function ;)

@SmOke_N

I work on it. It's ok for _ExcludeFileSet.

For excluding files, we must give the parameters like this -x!*.mp3 -x!*.avi

We can easily modify _ExcludeFileSet and _ExcludeArcSet function to do it.

But for including files, it's not so easy, If I do the same thing for _IncludeFileSet, the result is really surprising !!!

So actually I search what syntax to use, but I think that we must include the path (not sure). ^^

-i!$SearchPath*.mp3 -i!$SearchPath*.avi instead of -i!*.mp3 -i!*.avi

I will make search later on the journey.

Edit : After some testing, it seems that if you want to include multiple files, you must specify the path.

Also, I have made try with fileset, and it's the same problem.

If I use -i!*.mp3 -i!*.avi, the first parameter consider the search path, but not the second parameter!

Perhaps it's due to this dll ! In original documentation, we can read that multiple include switches are supported, but they don't explain how it must be used in multiple include...

Mr Tlem and SmOke_N both of your solutions worked prefectly for me. I chose Tlem's option because of SmOke_N said it would be better.

BUT i would like to tell you something;

I don't know how you are THAT good at programming with autoit.

AND I WOULD WORSHIP YOU instead of any god if i were a believer.

So thank you. Milion times. Not for just solving my problem.

But for beign awesome with your poetic code and helpfullness.

-- sorry for my english i got excited.

You are the BEST :)

sincerely, autoit lamer. see you with another question....

Link to comment
Share on other sites

Tanks.

But the goal is to make 7zip UDF (and others UDFs) more complete and robust, so autoit lamer are good to point us problems. ;)

Edit:

After testing and testing again (with 7z.exe and 7zip UDF), this is what I found.

For excluding files, it's really simple, we have just to separate switch like said before :

7z a archive.zip C:MyDir*.* -x!*.mp3 -x!*.avi

For including files, it's more delicate.

1st, we must indicate the directory of files that we wand to include.

2nd, the switch can be different depending if you want to include one file or multiple files and if you want do a recursive operation.

So, knowing this, let's take a look on what we must do.

If I want to put in archive all Au3Check.dat file of Autoit directory (not recurse) and all au3 file of AutoIt directory (recursively) and all chm files of Autoit directory (but not recursively), this is the 7z.exe command line:

7z.exe a c:AutoIt.zip "C:Program FilesAutoIt3Au3Check.dat" -ir!"C:Program FilesAutoIt3*.au3" -i!"C:Program FilesAutoIt3*.chm"

You can see that we must use -ir! for recursive include and -i! for not recursive include.

Now there is two tree choices to generate the switch :

1st: Never use recursive for including wildcard

2nd: Always use recursive for including wildcard

3rd: Add a special use of wildcard to activate the recursivity eg: "*.ext" => -i!*.ext and "**.ext" => -ir!*.ext

Personnaly, I think that most of the time, when we made zip archive and we want to include files with wildcard, it's for all the file of the directory. Now if not, updating the zip file with multiple operations is a good point. ;)

Waiting to read your notices, this is the modified _IncludeFileSet and _ExcludeFileSet functions :

Func _IncludeFileSet($sVal)
    If StringInStr($sVal, ";") Then
        Local $aVal = StringSplit($sVal, ";")
        $sVal = ""
        For $i = 1 to UBound($aVal) - 1
            If StringInStr($aVal[$i], "*") Then
                $sVal &= ' -ir!"' & $aVal[$i] & '"'
            Else
                $sVal &= ' -i!"' & $aVal[$i] & '"'
            EndIf
        Next
        Return $sVal
    ElseIf StringInStr($sVal, "*") Then
        Return ' -ir!"' & $sVal & '"'
    ElseIf StringLeft($sVal, 1) = "@" Then
        Return ' -i"' & $sVal & '"'
    Else
        Return ' -i!"' & $sVal & '"'
    EndIf
EndFunc   ;==>_IncludeFileSet

Func _ExcludeFileSet($sVal)
    If StringInStr($sVal, ";") Then
        Local $aVal = StringSplit($sVal, ";")
        $sVal = ""
        For $i = 1 to UBound($aVal) - 1
            $sVal &= ' -x!"' & $aVal[$i] & '"'
        Next
        Return $sVal
    ElseIf StringInStr($sVal, "*") Then
        Return ' -x!"' & $sVal & '"'
    ElseIf StringLeft($sVal, 1) = "@" Then
        Return ' -x"' & $sVal & '"'
    Else
        Return ' -x!"' & $sVal & '"'
    EndIf
EndFunc   ;==>_ExcludeFileSet

Now, in your opinion, must we do the same operation on _IncludeArcSet and _ExcludeArcSet functions ?

Edited by Tlem

Best Regards.Thierry

Link to comment
Share on other sites

  • Moderators

If you're asking me to respond, my opinion is anything that allows for multiple entries should be changed.

Also, I'm not a fan of declaring variables within a condition, can't even imagine that passing any debugger or au3check.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...