Anybody can help show examples of using libarchive to extract ZIP files to a specified folder? It looks like the sample programs provided (untar.c, tarfilter.c and minitar) all extracts the archive to the current working directory. Is there a way to say "extract to this folder and below" to libarchive and not clobber the program's active folder?
One of the main drivers is that the extraction code will be run in a background thread, and thus changing the program working directory may create problems. Also this will be used in an iOS application (iPhone, iPad), which is picky on what folders that the application can write to.
Thanks in advance.
You can rewrite each archive_entry's pathname before calling archive_read_extract. For example:
const char* path = archive_entry_pathname( entry );
char newPath[PATH_MAX + 1];
snprintf( newPath, PATH_MAX, "/SomeOtherDirectory/%s", path );
archive_entry_set_pathname( entry, newPath );
untar.c can be easily modified to do this by prepending the path you want to use to the pathname that is passed to create_dir() and create_file() from untar().
Note that untar.c is a standalone decompressor, seperate from libarchive.
The same effect is easily achievable with libarchive - it gives you full control over the creation of files and directories when unarchiving.
Related
In my matlab script I would like to output some files in a specific folder.
My function will accept a path to the desired folder and will check for its existance, but I would also like to implement a default behaviour consisting in saving everything in a default folder (named with day and time) located in the document folder of the computer.
Looking around I found some suggestion (get 'Documents' path in Matlab) on how to detect the correct folder in specific conditions (let's say a Windows PC, the default document folder, something with a specific name, ...). Is there anything more general, usable for all platforms (Win, Mac and Unix)? Or should I implement some switch?
Thanks.
Just making an answer out of Wolfie's comment.
Directly taken from Matlab documentation:
userpath('reset') sets the first folder on the search path to the
default for your platform. The default userpath folder is
platform-specific.
Windows® platforms — %USERPROFILE%/Documents/MATLAB.
Mac platforms — $home/Documents/MATLAB.
Linux® platforms — $home/Documents/MATLAB if $home/Documents exists.
I have a bunch of codes that are currently stored on my local machine. There are two folders, one called "Resources" and another called "src". There is one main script that needs to be run called "main.m" in "src" which calls files from "Resources".
If I copy this whole thing onto a new computer, the paths will change and MATLAB may not be able to find "Resources" anymore. I know that relative to "main.m", I need to go up one level and then into "Resources".
What is the best way of getting MATLAB to point to "Resources"?
I am currently trying along the lines of
P = mfilename('fullpath')
which gives the path for main.m. Now, I want to navigate from here, one folder up and then into "Resources". Or if there is a better way, please let me know.
Eventually, I want to extend it to work for multiple folders "Resources1", "Resources2" etc. so MATLAB needs to be able to navigate to the right folder.
You can get it like:
fullfile(fileparts(mfilename('fullpath')), '..', 'Resources');
Explanation:
mfilename('fullpath') will return the full path and name of the
M-file in which the call occurs, without the extension
fileparts will return the path of the passed file (only the containing directory)
fullfile will build the full directory specification from the folder names passed (Note: '..' always means the parent directory)
Based on this it is quite simple to write a function that gets the sibling directory of the directory containing the file:
getSiblingOfParentDirectory.m
function siblingDirPath = getSiblingOfParentDirectory(filepath, siblingDirName)
siblingDirPath = fullfile(fileparts(filepath), '..', siblingDirName);
end
then to use it in an M-file:
for i = 1:3
disp(getSiblingOfParentDirectory(mfilename('fullpath'), ['Resources', num2str(i)]));
end
Sample output:
D:\pathtest\Resources1
D:\pathtest\Resources2
D:\pathtest\Resources3
You can try the following:
ResourcesFolder = strrep(mfilename('fullpath'), 'src\main', 'Resources');
addpath(ResourcesFolder);
%%Your code here where you need those files
rmpath(ResourcesFolder);
Which is fully dependant on the names of your folders & files of course. Basically "addpath" enables you to access the files in the mentioned directory by adding it to the search path, and "rmpath" does the exact opposite.
Also, if you literally want to navigate to a folder present on one level up, you can execute the following:
cd ..\Resources
Which goes one level up, searches for the folder 'Resources', then changes the current directory to that folder .
After the upload the a sapui5 application on the SAP system has a strange structure. The files are not in the same structure as they were on my machine and the filenames are hashed, except MIMEs. So I am not able to find e.g. a specific "controller.js". The application is still fully working.
In this specific case the SAP Program "/UI5/UI5_REPOSITORY_LOAD" was used to upload the application. The upload protocol looks fine, no hint about renaming or similar. So I am not sure if the problem is with the system or the program.
All the hash files name should be normal naming and should be in sub-folders components. Even the "index.html" file has a hash, this cases a problem when click on "test application", because it opens the hash in the URL. The hash, which is the path and the filename cannot be opened, but if I replace the hash with the original path -> it works
http://scn.sap.com/thread/3809662
A work colleague found the issue in the sap system. It seems it is not allowed to have path + filename longer than 70 characters. If it is longer it hashes the path and filename to place it under the project root folder.
The german comment seems very strange, though ... "Name length should not be a
problem. Do we have anyhow a max length?"
It also creates a file containing the mapping from filepath + filename to hash.
You should not use file names longer than 70 characters.
Also you should not use '-' in your file names.
As far as I know the only allowed characters for valid BSP paths are:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./_"
I have added a lot of paths to matlab and now I want to share my code, but I don't know exactly which function (in which path) I should add to my shared code. Each time I need to add a missing function and it is really bothering for me and the users who are using the code.
So, I would like to restore the matlab path to its original case. Is there any way to do this in matlab? I also want to keep a backup of my current added path in a .m file and use it later when I am done.
To restore the path to default value - http://www.mathworks.com/help/matlab/ref/restoredefaultpath.html
restoredefaultpath sets the search path to include only folders for
MathWorks® installed products. Use restoredefaultpath when you are
having problems with the search path.
restoredefaultpath; matlabrc sets the search path to include only
folders for MathWorks installed products and corrects search path
problems encountered during startup.
And to save the current path - http://www.mathworks.com/help/matlab/ref/savepath.html
savepath updates the MATLAB® search path for all users on the system
so that the path can be reused in a future session. savepath saves the
search path to the pathdef.m file that MATLAB located at startup, or
to the current folder if a pathdef.m file exists there.
Or you can just store path in variable p = path; and restore it later path(p);. If the path is saved into pathdef.m the call of pathdef returns the string that can be used to set the saved path.
I wrote a MATLAB program with a GUI (to enter the measurement settings) and a measurement function which gets called when pressing "START" in the GUI.
In both I use separate files for sub functions to keep it easier to read and maintain.
The file structure looks something like this
C:/../folder/+measure/measure.m
C:/../folder/+measure/getData.m
C:/../folder/+measure/plot.m
C:/../folder/+measure/evalutate.m
C:/../folder/+measureGUI/getGuiData.m
C:/../folder/+measureGUI/calcLimits.m
C:/../folder/+measureGUI/saveGuiState.m
C:/../folder/+measureGUI/loadGuiState.m
C:/../folder/+measureGUI/background.png
C:/../folder/+measureGUI/guiState.mat
C:/../folder/measureGUI.fig
C:/../folder/measureGUI.m
This works, if I'm executing the measureGUI.m in "folder".
The current settings in the GUI are saved in the guiState.mat file when closing the GUI in saveGuiState.m
filename = '+autoProberGUI/guiState.mat';
save(filename, 'guiState');
And loaded (by loadGuiState.m) the next time the GUI gets opened.
Now I have to put the finished program on a network drive and add the folder to my matlab search path to call measureGUI.m.
The program works but it can't save or load the guiState.mat due to the relative path (I guess the path is relative to the folder I'm currently in, and not the folder the calling function is in).
I think I could include the subfolder to the search path or use an absolute path in filename. But both solutions seem to me to be not the proper way.
Is there a way to have relative paths to the file from where the function is located on the drive? Meaning relative to
I:/..NetworkDrive../folder/+measureGUI/saveGuiState.m
instead of relative from where I call measureGUI.m
(Sorry for the poor English, I hope it is not too confusing)
You can use pwd to get the full path to you current working directory.
Then you can concatenate with [pwd '/folder/+measureGUI/saveGuiState.m'].
To locate the function you can use which.