Too many files selected to pass to 7-zip command line.
Posted: 20 Jun 2011 03:51
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.
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.