LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2012, 01:08 AM   #1
laks
Member
 
Registered: Feb 2012
Posts: 34

Rep: Reputation: Disabled
Unhappy Passing List of files to 7zip exe


Hi,

I am writing a program in java which archives multiple files into one single archive. Number of files to be archived is decided at runtime. 7z manual says the list of files need to be passed as comma separated values to 7z exe. Only way I can see to achieve this is to create a StringBuilder object, parse through the list of files(stored in a list) and append each of these to the command. But this doesn't look like a neat solution to me. Could Any one help me out finding a more elegant solution to this.

Thanks,
Lakshmi
 
Old 04-09-2012, 03:03 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Actually such objects would neatly encapsulate what others would have to do. No need to reinvent the wheel.

But if you want, here is one pseudo code.

Initialise the command list.
If first file, then append file name.
Else append a comma and then a file name.

OK
 
Old 04-09-2012, 03:32 AM   #3
laks
Member
 
Registered: Feb 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Thanks Anita, when you say a command list, do you mean an Array of String. Something like,

String[] command =["",""].In that case, I did not find any way to insert files at runtime.
 
Old 04-09-2012, 12:30 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by laks View Post
7z manual says the list of files need to be passed as comma separated values to 7z exe.
No it doesn't.

Code:
Command Line Syntax
7z <command> [<switch>...] <base_archive_name> [<arguments>...]

<arguments> ::= <switch> | <wildcard> | <filename> | <list_file>
<switch>::= <switch_symbol><switch_characters>[<option>]
<switch_symbol> ::= '/' | '-' 
<list_file> ::= @{filename}
 
1 members found this post helpful.
Old 04-10-2012, 01:56 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
its not Anita but AnanthaP.

Now observe carefully.

Command list is just a string initially initialised to null.

Each time you append (concatenate (string+=)) an optional comma and then the next file name.

OK

But as ntubski said ... You dont even need the comma.

OK
 
1 members found this post helpful.
Old 04-10-2012, 10:31 PM   #6
laks
Member
 
Registered: Feb 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Thanks AnanthaP and ntubski.
 
Old 04-11-2012, 03:30 PM   #7
emanresu
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 76

Rep: Reputation: 15
i may be stating something obvious here, but Java comes with Zip classes, which in my own opinion makes it easier to create Zip archive files, and your get a self-contained java program without any external dependency on 7zip.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Passing a list of variables to a for loop pdr_dan Linux - Newbie 5 03-21-2011 12:38 PM
[SOLVED] Passing a paramter to a list of command in another file tqz Linux - Newbie 7 04-20-2010 05:27 AM
passing parameters from a unix shell prompt into a windows cmd.exe prompt nano2 Programming 1 09-01-2009 11:26 AM
C++ passing variable argument list to other functions R00ts Programming 8 08-08-2008 05:10 PM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration