Tar file extraction

I'm currently writing a tar file extractor and have come across the issue that the gem used "package" will only allow you to extract to the directory in which the file is. So my question being is there a way to extract to a different directory?

···

Sent from my iPhone

Hi Thomas,

You might want to check out the FileUtils#mv
<Module: FileUtils (Ruby 2.2.2);
method.

I hope this helps,

Cheers,
h

···

On Mon, Dec 21, 2015 at 7:15 AM, thomas Perkins <thomas.perkins23@icloud.com > wrote:

I'm currently writing a tar file extractor and have come across the issue
that the gem used "package" will only allow you to extract to the directory
in which the file is. So my question being is there a way to extract to a
different directory?

Sent from my iPhone

Depending on what you’re trying to do, Thomas, you may find the gem
`archive-tar-minitar` (https://github.com/halostatue/minitar\) useful. I’m
trying to find time to update it, but it does work for a bunch of cases.

···

On Mon, Dec 21, 2015 at 8:15 AM, thomas Perkins <thomas.perkins23@icloud.com > wrote:

I'm currently writing a tar file extractor and have come across the issue
that the gem used "package" will only allow you to extract to the directory
in which the file is. So my question being is there a way to extract to a
different directory?

Sent from my iPhone

--
Austin Ziegler • halostatue@gmail.com • austin@halostatue.ca
http://www.halostatue.ca/http://twitter.com/halostatue

I don't see how FileUtils are going to help me to extract a tar file...?

···

Sent from my iPhone

On Dec 21, 2015, at 10:22 AM, Hector Rios <that.hector@gmail.com> wrote:

Hi Thomas,

You might want to check out the FileUtils#mv method.

I hope this helps,

Cheers,
h

On Mon, Dec 21, 2015 at 7:15 AM, thomas Perkins <thomas.perkins23@icloud.com> wrote:
I'm currently writing a tar file extractor and have come across the issue that the gem used "package" will only allow you to extract to the directory in which the file is. So my question being is there a way to extract to a different directory?

Sent from my iPhone

Hi Thomas,

The idea is that you'll untar the file and after it's extracted from your
present working directory, you can move them to where you need to.

Cheers,
h

···

On Mon, Dec 21, 2015 at 6:54 PM, thomas Perkins <thomas.perkins23@icloud.com > wrote:

I don't see how FileUtils are going to help me to extract a tar file...?

Sent from my iPhone

On Dec 21, 2015, at 10:22 AM, Hector Rios <that.hector@gmail.com> wrote:

Hi Thomas,

You might want to check out the FileUtils#mv
<http://ruby-doc.org/stdlib-2.2.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-move&gt;
method.

I hope this helps,

Cheers,
h

On Mon, Dec 21, 2015 at 7:15 AM, thomas Perkins < > thomas.perkins23@icloud.com> wrote:

I'm currently writing a tar file extractor and have come across the issue
that the gem used "package" will only allow you to extract to the directory
in which the file is. So my question being is there a way to extract to a
different directory?

Sent from my iPhone

I got that but I'm looking for a way to untar the file to a different directory, without having to do the extra steps

···

Sent from my iPhone

On Dec 21, 2015, at 7:06 PM, Hector Rios <that.hector@gmail.com> wrote:

Hi Thomas,

The idea is that you'll untar the file and after it's extracted from your present working directory, you can move them to where you need to.

Cheers,
h

On Mon, Dec 21, 2015 at 6:54 PM, thomas Perkins <thomas.perkins23@icloud.com> wrote:
I don't see how FileUtils are going to help me to extract a tar file...?

Sent from my iPhone

On Dec 21, 2015, at 10:22 AM, Hector Rios <that.hector@gmail.com> wrote:

Hi Thomas,

You might want to check out the FileUtils#mv method.

I hope this helps,

Cheers,
h

On Mon, Dec 21, 2015 at 7:15 AM, thomas Perkins <thomas.perkins23@icloud.com> wrote:
I'm currently writing a tar file extractor and have come across the issue that the gem used "package" will only allow you to extract to the directory in which the file is. So my question being is there a way to extract to a different directory?

Sent from my iPhone

You could open the input file (the tar file) and then start a subprocess which would inherit the input file. Then have the subprocess cd to the desired output directory, do the extraction, and then exit. The parent process waits until the subprocess exits and then continues.

Or you could get the process' current working directory, open the input file, cd to the desired output directory, do the extract, and then cd back.

Or get the current working directory and use it to build the absolute pathname of the input file. Then cd to the output directory, open the input file via its absolute path name, and do the extraction (this leaves the process in a different directory to where it started).

Graham

···

On 22/12/2015 12:07 PM, thomas Perkins wrote:

I got that but I'm looking for a way to untar the file to a different directory, without having to do the extra steps

Sent from my iPhone

On Dec 21, 2015, at 7:06 PM, Hector Rios <that.hector@gmail.com > <mailto:that.hector@gmail.com>> wrote:

Hi Thomas,

The idea is that you'll untar the file and after it's extracted from your present working directory, you can move them to where you need to.

Cheers,
h

On Mon, Dec 21, 2015 at 6:54 PM, thomas Perkins >> <thomas.perkins23@icloud.com <mailto:thomas.perkins23@icloud.com>> wrote:

    I don't see how FileUtils are going to help me to extract a tar
    file...?

    Sent from my iPhone

    On Dec 21, 2015, at 10:22 AM, Hector Rios <that.hector@gmail.com >> <mailto:that.hector@gmail.com>> wrote:

    Hi Thomas,

    You might want to check out the FileUtils#mv
    <Module: FileUtils (Ruby 2.2.2);
    method.

    I hope this helps,

    Cheers,
    h

    On Mon, Dec 21, 2015 at 7:15 AM, thomas Perkins >>> <thomas.perkins23@icloud.com >>> <mailto:thomas.perkins23@icloud.com>> wrote:

        I'm currently writing a tar file extractor and have come
        across the issue that the gem used "package" will only allow
        you to extract to the directory in which the file is. So my
        question being is there a way to extract to a different
        directory?

        Sent from my iPhone

That might work... Thank you

···

Sent from my iPhone

On Dec 22, 2015, at 2:04 AM, Quintus <quintus@quintilianus.eu> wrote:

Graham Menhennitt <graham@menhennitt.com.au> writes:

Or you could get the process' current working directory, open the
input file, cd to the desired output directory, do the extract, and
then cd back.

Ruby’s Dir.chdir method allows this in a quite convenient way by
executing its optional block in the changed directory, then
automatically changing back from whereever it came:

Dir.chdir("/your/target/directory") do
   # Extract your tarball here
end
# Back in normal pwd

Greetings
Marvin

--
#!/sbin/quintus
Blog: http://www.guelkerdev.de

GnuPG key: F1D8799FBCC8BC4F

Graham Menhennitt <graham@menhennitt.com.au> writes:

Or you could get the process' current working directory, open the
input file, cd to the desired output directory, do the extract, and
then cd back.

Ruby’s Dir.chdir method allows this in a quite convenient way by
executing its optional block in the changed directory, then
automatically changing back from whereever it came:

  Dir.chdir("/your/target/directory") do
    # Extract your tarball here
  end
  # Back in normal pwd

Greetings
Marvin

···

--
#!/sbin/quintus
Blog: http://www.guelkerdev.de

GnuPG key: F1D8799FBCC8BC4F