If I understand you correctly, you have an archive file in some directory, (you called it "dir_2"), and you want to extract it into another directory, (which you called "dir_3")?
Right. tar will, by default, extract into your current working directory, reinstating the hierarchy specified within the archive itself, relative to current directory as prefix. Thus, provided you didn't make the grave error of creating the archive with absolute path names:
$ cd d:\path\to\dir_3
$ tar xvf d:\path\to\dir_2\archive.tar
should achieve what you want. (If you did create the archive, specifying absolute path names for the archived files, then I fear tar will always extract back to the same absolute paths; the moral is: never specify absolute path names for the files you add to a tar archive, always use a relative path).
In an earlier post, you said you did:
$ cd dir_2
$ tar xvf archive.tar -C dir_3
(exploiting the GNU tar -C extension feature), and it didn't work. I've never seen that fail, (but then, I use the MSYS implementation of GNU tar, rather than GnuWin32's). When you invoked that command, did your "dir_3" already exist as a subdirectory of "dir_2"? (Hint: tar will try to cd to the directory specified with -C; if it doesn't exist, that must fail; tar will not call mkdir for you).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
windows. im try to use tar to untar files to specified folder:
the line i use:
cd dir_2
tar -xvf archive.tar -C dir_3
error occur: error ... dir_2\dir_3: invalid argument
I try but in --help no key or switch for definite destination folder to untar
If I understand you correctly, you have an archive file in some directory, (you called it "dir_2"), and you want to extract it into another directory, (which you called "dir_3")?
Right. tar will, by default, extract into your current working directory, reinstating the hierarchy specified within the archive itself, relative to current directory as prefix. Thus, provided you didn't make the grave error of creating the archive with absolute path names:
$ cd d:\path\to\dir_3
$ tar xvf d:\path\to\dir_2\archive.tar
should achieve what you want. (If you did create the archive, specifying absolute path names for the archived files, then I fear tar will always extract back to the same absolute paths; the moral is: never specify absolute path names for the files you add to a tar archive, always use a relative path).
In an earlier post, you said you did:
$ cd dir_2
$ tar xvf archive.tar -C dir_3
(exploiting the GNU tar -C extension feature), and it didn't work. I've never seen that fail, (but then, I use the MSYS implementation of GNU tar, rather than GnuWin32's). When you invoked that command, did your "dir_3" already exist as a subdirectory of "dir_2"? (Hint: tar will try to cd to the directory specified with -C; if it doesn't exist, that must fail; tar will not call mkdir for you).
Try to use bsdtar from the libarchive package.