Command for WinRAR on specific file

1.1k views Asked by At

I have a code to archive a ZIP file into another ZIP file, using command like this:

String rootftp = "C:\\ROOT_DIR_PUSHFILE\\";
    String tampungString = "AAA\\PFILE\\AAA20140531.zip";
    String password = "testing";

    String command = "cmd.exe "
            + "/C"
            + " cd C:\\Program Files\\WinRAR \n"
            +" && rar a -n "+rootftp.trim()+tampungString+".zip"+" "+ rootftp.trim()+tampungString + " -p"+password.trim();
    System.out.println(command);

    File file = new File(rootftp.trim()+tampungString);
        try {
            Runtime.getRuntime().exec(command);
            file.delete();
        } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }

But the result is :

enter image description here

When I try to archive a specific file, the results is always archive from root directory, not just the specific file, like AAA20140531.zip file, can you explain, why? And how to fix it?

1

There are 1 answers

1
Hana Bzh On BEST ANSWER

Use this command to create .rar without parent folder:

rar a -ep1 c:\ROOT_DIR_PUSHFILE\AAA\PFILE\AAA20140531.zip c:\ROOT_DIR_PUSHFILE\AAA\PFILE\ -p123456

-ep1 switch makes the result to exclude the base folder from the paths,