I've been trying to use the system(cmd) call in C to tar multiple files together.
When i do so i specify the absolute paths of the tar file as well as the files to be included in the tar file.
I was expecting that upon extraction of example.tar i'd get 1.xml,2.xml and 3.xml. However upon extraction 'mnt' and 'john' directories are again created in the extraction directory and inside these reside the desired xml files.
Is there a way i can prevent these directories from being created and get only the xml files upon extraction?
tar always preserves paths, so the only way to do what you want is to change to the directory where the files are, and add them from there using just thier name not path/name
Thanks Wempy !
How do i change the current directory using C ?
Does system("cd /mnt/john/"); work?
or do i use the chroot() system call ? But this would alter the system's root directory. I could change it back to / again though when my process is terminated.