Compress a folder using tar in MATLAB - matlab

I try compress a folder in MATLAB using tar. I want to assign the current date as the name of the archive file. When I try
tar 'datestr(now)' FooFolder
Nothing happens. With
tar datestr(now) FooFolder
the name of the archive file is datestr(now).tar as expected. What is the solution?

The documentation is quite clear, use the function syntax:
tar(tarfilename,files)
Example:
tar(datestr(now),'FooFolder')

Related

How merge gz files from postgres dump into one big file?

There is a folder with postgres dump files like:
0001.dat.gz
0001.dat.gz
...
6000.dat.gz
toc.dat
How merge all these files into single gz archive which is recognized by postgres during restoring?
So it looks like you have the directory format. pg_restore will recognize that format. I don't think there is any supported way to convert it to one of the other formats. You can tar it up into a single file, but you will have to untar it before restoring. Next time you run pg_dump, you should tell it to use the format you want used.
There are subtle differences in the toc.dat file between the directory format and the tar format, so if you just uncompress and then tar up the directory, it will not work (at least in my hands). It does work the other way around, however.

Is it possible to set output directory for triangle program from triangle package?

I see no way to set destination directory or file here: http://www.cs.cmu.edu/~quake/triangle.switch.html
Actually, the program places result file in the same directory, even if current directory is different.
Why? Is ti possible to change?
The output files for the program are generated from the input file names. You can see this from the source code on line 3586
strcpy(b->outnodefilename, b->innodefilename);
...
strcat(b->outnodefilename, ".node");
strcat(b->outelefilename, ".ele");
...
Because of that I don't think there is a way to set the output directory as an option. It seems you will need to manually copy the output files to a different directory
cp output.node your/output/dir/output.node && rm output.node

How to extract .gz file with .txt extension folder?

I'm currently stuck with this problem where my .gz file is "some_name.txt.gz" (the .gz is not visible, but can be recognized with File::Type functions),
and inside the .gz file, there is a FOLDER with the name "some_name.txt", which contains other files and folders.
However, I am not able to extract the archive as you would manually (the folder with the name "some_name.txt" is extracted along with its contents) when calling the extract function from the Archive::Extract because it will just extract the "some_name.txt" folder as a .txt file.
I've been searching the web for answers, but none are correct solutions. Is there a way around this?
From Archive::Extract official doc
"Since .gz files never hold a directory, but only a single file;"
I would recommend using tar on the folder and then gz it.
That way you can use Archive::Tar to easily extract specific file:
Example from official docs:
$tar->extract_file( $file, [$extract_path] )
Write an entry, whose name is equivalent to the file name provided to disk. Optionally takes a second parameter, which is the full native path (including filename) the entry will be written to.
For example:
$tar->extract_file( 'name/in/archive', 'name/i/want/to/give/it' );
$tar->extract_file( $at_file_object, 'name/i/want/to/give/it' );
Returns true on success, false on failure.
Hope this helps.
Maybe you can identify these files with File::Type, rename them with .gz extension instead of .txt, then try Archive::Extract on it?
A gzip file can only contain a single file. If you have an archive file that contains a folder plus multiple other files and folders, then you may have a gzip file that contains a tar file. Alternatively you may have a zip file.
Can you give more details on how the archive file was created and a listing of it contents?

Linux zip command - adding date elements to file name

occasionally I run a backup of my phpbb forum files from the Shell command line:
zip -r forum_backup ~/public_html/forum/*
I'd like to add date elements to the file name, so that the zip file created is automatically formed as
forum_backup_05182013.zip
any other similar current date format would also be acceptable
now=$(date +"%m%d%Y")
zip -r forum_backup_$now ~/public_html/forum/
Without defining a variable first you can do it in one line with
zip -r "forum_backup_$(date +"%Y-%m-%d").zip" filelist
As taken from here
the following shell command, change the format as you want
FORMAT="%Y%m%d"
_DATE=$(date +"$FORMAT" )
zip -r "forum_bakcup_${_DATE}" ~/public_html/forum/*

How to extract and join files in Matlab

I have three files 1.zip, 1.z01 1.z02. I would like to extract and join them into a file.
In Ubuntu command line I'm using zip -FF name.zip --out name_joinde.zip
I would like to do this in Matlab, but with the zip command I'm getting an Invalid zip file error. How can I joint this files?
You cannot do it in one shot. But it is easy to do systematically using the zip and unzip commands:
%% Unzip files into "tempdir" directory (will create the directory if needed)
unzip('MyFruits.zip', 'tempdir')
unzip('MyColors.zip', 'tempdir')
%% Zip all files in "tempdir" directory into Joined.zip
zip('Joined.zip', '*.*', 'tempdir')
%% Delete the "tempdir" directory and all of its subdirectories
rmdir('tempdir', 's')
Try using the
unzip(..)
command first, and then
zip(..)
How about just using ! or system to call the Ubuntu command directly from within MATLAB?