Page 1 of 1

Too many files selected to pass to 7-zip command line.

Posted: 20 Jun 2011 03:51
by Meester
I'm having an issue with running 7-Zip form a script. My situation is this. Using XYplorer I do a search for all the files in a specified project that are before a certain date. I then need to put all these files in a ZIP file and archive them. I thought I would make a script that would ask me the name of the ZIP file and then zip up all of the files that I have selected from my search. Depending on the circumstances I might not want to archive all the file that were found in the search, so that's why I would select the ones that I want archived.

In short; I need a script that will zip up all the select files to one user specified zip file. I started with this simple script:

input $n, "Enter the NAME and LOCATION of Archive file";
run "C:\Program Files\7-Zip\7z.exe" "a" "-tzip" "$n" <selitems>, , 1;


But If I have too many files selected the command line becomes too long and it will not execute. So I thought I would run it separately for each file that was selected and I did it like this:

input $n, "Enter the NAME and LOCATION of Archive file";
$filelist = getinfo('SelectedItemsPathNames', '|'); //collect list of selected files
$count = 1;
$filename=gettoken($filelist,$count,"|"); //get first filename from filelist
$stop = 1;
while($stop == 1)
{
run "C:\Program Files\7-Zip\7z.exe" "a" "-tzip" "$n" "$filename", , 1;
$count++; // add number to count
$filename=gettoken($filelist,$count,"|"); // get next filename from filelist
if("$filename"==""){$stop == 2;} // if end of list break out of while loop
} // end while


The problem with this is that now it will start the next instance of adding to the zip file before the last instance was done. Thus only some of the files get added while others error out.

7zip does have exit codes that I thought maybe I could have it pause until the exitcode equaled something. But XYplorer doesn't have a way to see what the system variable %errorcode% is.

I'm a novice scripter so please be kind. :(

Re: Too many files selected to pass to 7-zip command line.

Posted: 20 Jun 2011 09:52
by nas8e9
7-Zip can take a list file (containing the file names you want to act on) instead of file names, as a parameter. This is described in the Command Line Version > Syntax section of 7-Zip''s help file.

Re: Too many files selected to pass to 7-zip command line.

Posted: 21 Jun 2011 02:44
by Meester
nas8e9 wrote:7-Zip can take a list file (containing the file names you want to act on) instead of file names, as a parameter. This is described in the Command Line Version > Syntax section of 7-Zip''s help file.
I didn't mention it because I was trying to keep my post simple but I tried that. Believe it or not all the names in the file get pushed to the command line and I end up with the same error of "To many characters in the command line". I couldn't believe it, I thought that would have been the perfect solution.

Re: Too many files selected to pass to 7-zip command line.

Posted: 21 Jun 2011 02:53
by nas8e9
Meester wrote:
nas8e9 wrote:7-Zip can take a list file (containing the file names you want to act on) instead of file names, as a parameter. This is described in the Command Line Version > Syntax section of 7-Zip''s help file.
I didn't mention it because I was trying to keep my post simple but I tried that. Believe it or not all the names in the file get pushed to the command line and I end up with the same error of "To many characters in the command line". I couldn't believe it, I thought that would have been the perfect solution.
That's indeed very unhelpful. Plan B, though not elegant, would be to have XYplorer create a batch file, with the first line initially creating the archive and adding the first file through 7-Zip's Add command and subsequent lines adding files to the archive through the Update command.

Re: Too many files selected to pass to 7-zip command line.

Posted: 21 Jun 2011 07:24
by Stefan

Re: Too many files selected to pass to 7-zip command line.

Posted: 21 Jun 2011 20:21
by Meester
That's indeed very unhelpful. Plan B, though not elegant, would be to have XYplorer create a batch file, with the first line initially creating the archive and adding the first file through 7-Zip's Add command and subsequent lines adding files to the archive through the Update command.
Now that is an interesting idea. Thanks.

Re: Too many files selected to pass to 7-zip command line.

Posted: 21 Jun 2011 20:25
by Meester
Stefan wrote:Perhaps that thread is helpful for you > length of string that can be passed to the command line / use SUBST
This is helpful, but what not sure how to incorporate that as of yet, but I'm still thinking it through. Thanks for your input.

Re: Too many files selected to pass to 7-zip command line.

Posted: 07 Jul 2011 18:26
by lukescammell