happy2help Posted May 9, 2009 Share Posted May 9, 2009 (edited) Sorry every1 I'm being blond. How do i use FileOpenDialog (or any other similar command) and put it in a array called $ArchiveFile. sometimes i may only want it to loop 2 times, other times 10 times. expandcollapse popup#include <UnRAR.au3> #include <File.au3> Global $Cancel = False HotKeySet("{Esc}", "_CancelUnpack") Dim $ArchiveFile $OutputFolder = FileSelectFolder("Browse for output path", "", 1) ;If $OutputFolder = "" Then Exit $ArchiveFile[1] = FileOpenDialog("Select the archive file", $OutputFolder, "Archive files (*.rar)") $ArchiveFile[2] = FileOpenDialog("Select the archive file", $OutputFolder, "Archive files (*.rar)") $ArchiveFile[3] = FileOpenDialog("Select the archive file", $OutputFolder, "Archive files (*.rar)") $ArchiveFile[4] = FileOpenDialog("Select the archive file", $OutputFolder, "Archive files (*.rar)") $ArchiveFile[5] = FileOpenDialog("Select the archive file", $OutputFolder, "Archive files (*.rar)") ; Read in lines of text until the EOF is reached For $x = 1 to 5 ;Creates a user-defined DLL Callback function to process Unrar events $hUnRAR_CallBack = DllCallbackRegister("_UnRARProc", "int", "uint;int;int;int") ;Retrieve comment from archive file $comment = _Rar_GetComment($ArchiveFile[$x]) ConsoleWrite("!> Archive comment: " & $comment & @LF) ;Open RAR archive and allocate memory structures $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, @error, "Archive open error") Exit EndIf $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, "UnRAR", "Archive open error") Exit EndIf ;Set a user-defined callback function to process Unrar events _RAR_SetCallback($hArchive, $hUnRAR_CallBack) ;Read header of file in archive, performs action and moves the current position in the archive to the next file ;Also extract or test the current file from the archive _Rar_UnpackArchive($hArchive, $OutputFolder) If @error Then MsgBox(16, "UnRAR", "Archive unpacking error") Exit EndIf If $Cancel = True Then MsgBox(64, "UnRAR", "Unpacking cancelled") Else MsgBox(64, "Done", "Archive unpacked") EndIf DllCallbackFree($hUnRAR_CallBack) Next Func _CancelUnpack() $Cancel = True EndFunc ;==>_CancelUnpack Func _UnRARProc($Msg, $UserData, $P1, $P2) Switch $Msg Case $UCM_PROCESSDATA;Return a positive value to continue process or -1 to cancel the archive operation If $Cancel = True Then Return -1 Case $UCM_NEEDPASSWORD;DLL needs a password to process archive Local $iPassGet = InputBox("Password required", "Please type a password", "", "*", 300, 120) If $iPassGet = "" Then Return -1;If user cancelled password entering Local $PassBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($PassBuffer, 1, $iPassGet) Return 1 Case $UCM_CHANGEVOLUME;Process volume change If $P2 = $RAR_VOL_ASK Then;Required volume is absent Local $iVolGet = InputBox("Next volume required", "Please type a path to the next volume", "", "", 300, 120) If $iVolGet = "" Then Return -1;If user cancelled path entering Local $VolBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($VolBuffer, 1, $iVolGet) Return 1 EndIf EndSwitch EndFunc ;==>_UnRARProc be gentle. it's my birthday today Edited May 9, 2009 by happy2help Link to comment Share on other sites More sharing options...
monoceres Posted May 9, 2009 Share Posted May 9, 2009 (edited) Happy birthday then. ; Adds files to the array until users press cancel Local $Arr[1] Do $file=FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") If $file="" Then ExitLoop If UBound($Arr)>1 Then ReDim $Arr[UBound($Arr)+1] $Arr[UBound($Arr)-1]=$file Until False Edited May 9, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
happy2help Posted May 10, 2009 Author Share Posted May 10, 2009 (edited) Happy birthday then. ; Adds files to the array until users press cancel Local $Arr[1] Do $file=FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") If $file="" Then ExitLoop If UBound($Arr)>1 Then ReDim $Arr[UBound($Arr)+1] $Arr[UBound($Arr)-1]=$file Until False I have taken your code and think i have used it correctly. please advise me otherwise. expandcollapse popup#include <UnRAR.au3> ;#include <File.au3> $copy1 = FileInstall("unrar.dll", "c:\windows\unrar.dll", 1) If Not $copy1 = 1 Then Exit Global $Cancel = False HotKeySet("{Esc}", "_CancelUnpack") $OutputFolder = FileSelectFolder("Browse for output path", "H:\To Burn\To Laptop\", 1) If $OutputFolder = "" Then Exit $InputFolder = FileSelectFolder("Browse for output path", "H:\To Burn\", 1) If $InputFolder = "" Then Exit ; Adds files to the array until users press cancel Local $ArchiveFile[1] Do $file=FileOpenDialog("Select the archive file", $InputFolder, "Archive files (*.rar)") If $file="" Then ExitLoop If UBound($ArchiveFile)>1 Then ReDim $ArchiveFile[UBound($ArchiveFile)+1] $ArchiveFile[UBound($ArchiveFile)-1]=$file Until False ; Read in lines of text until the EOF is reached For $x = 1 to 5 ;Creates a user-defined DLL Callback function to process Unrar events $hUnRAR_CallBack = DllCallbackRegister("_UnRARProc", "int", "uint;int;int;int") ;Retrieve comment from archive file $comment = _Rar_GetComment($ArchiveFile[$x]) ConsoleWrite("!> Archive comment: " & $comment & @LF) ;Open RAR archive and allocate memory structures $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, @error, "Archive open error") Exit EndIf $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, "UnRAR", "Archive open error") Exit EndIf ;Set a user-defined callback function to process Unrar events _RAR_SetCallback($hArchive, $hUnRAR_CallBack) ;Read header of file in archive, performs action and moves the current position in the archive to the next file ;Also extract or test the current file from the archive SplashTextOn("Unpacking Now", "Unpacking " & $ArchiveFile & @CRLF & "Please wait a while.", 640, 480, -1, -1, 4, "", 24) _Rar_UnpackArchive($hArchive, $OutputFolder) If @error Then MsgBox(16, "UnRAR", "Archive unpacking error") Exit EndIf SplashOff() If $Cancel = True Then MsgBox(64, "UnRAR", "Unpacking cancelled") Else MsgBox(64, "Done", "Archive unpacked") EndIf DllCallbackFree($hUnRAR_CallBack) Next Func _CancelUnpack() $Cancel = True EndFunc;==>_CancelUnpack Func _UnRARProc($Msg, $UserData, $P1, $P2) Switch $Msg Case $UCM_PROCESSDATA;Return a positive value to continue process or -1 to cancel the archive operation If $Cancel = True Then Return -1 Case $UCM_NEEDPASSWORD;DLL needs a password to process archive Local $iPassGet = InputBox("Password required", "Please type a password", "", "*", 300, 120) If $iPassGet = "" Then Return -1;If user cancelled password entering Local $PassBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($PassBuffer, 1, $iPassGet) Return 1 Case $UCM_CHANGEVOLUME;Process volume change If $P2 = $RAR_VOL_ASK Then;Required volume is absent Local $iVolGet = InputBox("Next volume required", "Please type a path to the next volume", "", "", 300, 120) If $iVolGet = "" Then Return -1;If user cancelled path entering Local $VolBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($VolBuffer, 1, $iVolGet) Return 1 EndIf EndSwitch EndFunc;==>_UnRARProc BTW Thanks for the quick response and help Just tested this and get this error C:\Users\Public\Backup\Downloads\UnRarMe.au3 (31) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $comment = _Rar_GetComment($ArchiveFile[$x]) $comment = _Rar_GetComment(^ ERROR - help!! Edited May 10, 2009 by happy2help Link to comment Share on other sites More sharing options...
monoceres Posted May 10, 2009 Share Posted May 10, 2009 Any thought about this? For $x = 1 to 5 Since you cannot know how big the array is going to be (that's up to the user) yuo should format your loop like this: For $x=0 To Ubound($ArchiveFile)-1 Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
happy2help Posted May 10, 2009 Author Share Posted May 10, 2009 Happy birthday then. ; Adds files to the array until users press cancel Local $Arr[1] Do $file=FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") If $file="" Then ExitLoop If UBound($Arr)>1 Then ReDim $Arr[UBound($Arr)+1] $Arr[UBound($Arr)-1]=$file Until False How do i retrieve the array / variables as i have tried these MsgBox(16, "Test", $file) MsgBox(16, "Test", $Arr) MsgBox(16, "Test", $Arr[1]) I get no info from these What is the array i should be using so i can use the info later in the script? Link to comment Share on other sites More sharing options...
monoceres Posted May 10, 2009 Share Posted May 10, 2009 Oops, there was a small error in my script. Change If UBound($Arr)>1 Then ReDim $Arr[UBound($Arr)+1] To If UBound($Arr)=1 Then ReDim $Arr[UBound($Arr)+1] Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
happy2help Posted May 10, 2009 Author Share Posted May 10, 2009 Local $Arr[1] Do $file=FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") If $file="" Then ExitLoop If UBound($Arr)=1 Then ReDim $Arr[UBound($Arr)+1] $Arr[UBound($Arr)-1]=$file Until False MsgBox(16, "Test", $Arr[1]) MsgBox(16, "Test", $Arr[2]) MsgBox(16, "Test", $Arr[3]) i select 3 files and $Arr[1] displays the 3rd file name, what about the first 2? Link to comment Share on other sites More sharing options...
monoceres Posted May 10, 2009 Share Posted May 10, 2009 Damn, I'm stupid today. #include <array.au3> Local $Arr[1] Do $file=FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") If $file="" Then ExitLoop If $Arr[0]<>"" Then ReDim $Arr[UBound($Arr)+1] $Arr[UBound($Arr)-1]=$file Until False _ArrayDisplay($Arr) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
happy2help Posted May 10, 2009 Author Share Posted May 10, 2009 (edited) I think i've cracked it. here is my full script so everyone can use it. It allows you to unpack multiple Rar Files into a single folder, one after another. expandcollapse popup#include <UnRAR.au3> #include <File.au3> #include <Array.au3> Local $ArchiveFile[1] Global $Cancel = False HotKeySet("{Esc}", "_CancelUnpack") ;$copy1 = FileInstall("unrar.dll", "unrar.dll", 1) ;If Not $copy1 = 1 Then Exit $oFolder = "H:\To Burn\To Laptop\" If Not FileExists($oFolder) Then $oFolder = "D:\Laptop\Unpacked\"; set for testing purposes $iFolder = "H:\To Burn\" If Not FileExists($iFolder) Then $iFolder = "D:\Laptop\Unpacked\"; set for testing purposes $OutputFolder = FileSelectFolder("Browse for output path", $oFolder, 1) If $OutputFolder = "" Then Exit ; if its cancelled then exit script $InputFolder = FileSelectFolder("Browse for output path", $iFolder, 1) If $InputFolder = "" Then Exit ; if its cancelled then exit script $ArchiveFile[0] = FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") ;_ArrayDisplay($ArchiveFile, "$ArchiveFile BEFORE _ArrayAdd()") Do $ask = FileOpenDialog("Select the archive file", "", "Archive files (*.rar)") if $ask = "" Then ExitLoop ; if its cancelled then no more files to add _ArrayAdd($ArchiveFile, $ask) ;_ArrayDisplay($ArchiveFile, "$ArchiveFile AFTER _ArrayAdd()") Until False MsgBox(16, "Test", $ArchiveFile[0],2) ; set for testing purposes MsgBox(16, "Test", $ArchiveFile[1],2) ; set for testing purposes MsgBox(16, "Test", $ArchiveFile[2],2) ; set for testing purposes ; Read in lines of text until the EOF is reached For $x=0 To Ubound($ArchiveFile)-1 ;Creates a user-defined DLL Callback function to process Unrar events $hUnRAR_CallBack = DllCallbackRegister("_UnRARProc", "int", "uint;int;int;int") ;Open RAR archive and allocate memory structures $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, @error, "Archive open error") Exit EndIf $hArchive = _RAR_OpenArchive($ArchiveFile[$x]) If @error Then MsgBox(16, "UnRAR", "Archive open error") Exit EndIf ;Set a user-defined callback function to process Unrar events _RAR_SetCallback($hArchive, $hUnRAR_CallBack) ;Read header of file in archive, performs action and moves the current position in the archive to the next file ;Also extract or test the current file from the archive SplashTextOn("Unpacking Now", "Unpacking " & $ArchiveFile[$x] & @CRLF & "Please wait a while.", 640, 480, -1, -1, 4, "", 24) _Rar_UnpackArchive($hArchive, $OutputFolder) If @error Then MsgBox(16, "UnRAR", "Archive unpacking error") Exit EndIf SplashOff() If $Cancel = True Then MsgBox(64, "UnRAR", "Unpacking cancelled") Else MsgBox(64, "Done", "Archive unpacked",2) EndIf DllCallbackFree($hUnRAR_CallBack) Next Func _CancelUnpack() $Cancel = True EndFunc ;==>_CancelUnpack Func _UnRARProc($Msg, $UserData, $P1, $P2) Switch $Msg Case $UCM_PROCESSDATA;Return a positive value to continue process or -1 to cancel the archive operation If $Cancel = True Then Return -1 Case $UCM_NEEDPASSWORD;DLL needs a password to process archive Local $iPassGet = InputBox("Password required", "Please type a password", "", "*", 300, 120) If $iPassGet = "" Then Return -1;If user cancelled password entering Local $PassBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($PassBuffer, 1, $iPassGet) Return 1 Case $UCM_CHANGEVOLUME;Process volume change If $P2 = $RAR_VOL_ASK Then;Required volume is absent Local $iVolGet = InputBox("Next volume required", "Please type a path to the next volume", "", "", 300, 120) If $iVolGet = "" Then Return -1;If user cancelled path entering Local $VolBuffer = DllStructCreate("char[256]", $P1) DllStructSetData($VolBuffer, 1, $iVolGet) Return 1 EndIf EndSwitch EndFunc ;==>_UnRARProc Please feel free to add any improvements or tweaks Edited May 10, 2009 by happy2help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now