File Path with the file name as a variable - unicode

I have a code that selects a zip folder from a path. My problem is the zip folder name will always be different. The path will always be the same though.
Example: "C\Users\name\Customer\New_Archive_022820186S12.zip"
I would like to make the zip folder as a variable so any zip folder will be picked up regardless of the name. In the example above the folder name is New_Archive_022820186S12.zip
What I'm looking for is a path name where the zip folder in the path is a variable
Suggestions?
Hi in C++ language. Thanks so much

Store the folder path and filename in separate variables, and then you can concatenate them together when needed eg:
std::string folder = "C:\\Users\\name\\Customer\\";
std::string filename = "New_Archive_022820186S12.zip"; // <-- populate as needed...
std::string zipfile = folder + filename;
// use zipfile as needed...

Related

How to add user created .mat files to the search path after compilation

How can I allow user to add additional dependenies after the source code was compiled with mcc.
I was thinking about an empty folder next to the executable, where the users can add the needed .mat-files, but I can't add the folder path to my executable (since addpath is not allowed in deployed applications).
Any ideas?
This answer assumes that your code can be customised by data contained in one or more .mat files at runtime.
You can point your code to look at a folder where the optional .mat file(s) would be located.
For example in the users home folder with a sub folder being the name of your application (or in the local app data) or whereever...
If you want it in a sub folder where the exe is, you can do this as well, you find the exe path using (on windows):
[status, result] = system('path');
installpath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
fprintf ( 'The exe install path is "%s"\n', installpath );
Then your code looks to load for example:
file2load = fullfile ( installpath, 'subFolder', 'runtimeCustomisation.mat' )
if exist ( file2load, 'file' ) == 2
"doSomething with the file"
end
Or something like that.
Recall that this is for dependencies which are .mat files only.

Zip files using 7zip from command window

Using 7zip, I want to give a location of a folder of files something like...
D:\Home\files Then I want it to zip all the files in that folder and leave them there. So for example zipme.txt become zipme.zip, so all files would keep their name but just become a zip file. I have tried to use
FOR %i IN (D:\Home\files) DO 7z.exe a "%~ni.zip"
But when I do it it adds a zip file for the directory so my output would be in the correct folder but would contain
D:\Home\files\file.zip
D:\Home\files\zipme.zip
zipped files also all items in directory like..
zipme.txt
zipme2.txt
D:\Home\files/zipme2.zip
So how can I zip each file individual in a folder and have the new zipped name be the individual files name
Was able to get this to work.
FOR %i IN (D:\Home\files\*) DO 7z.exe a "%~ni.zip" "%i"

reading several text files in a same script

I have a question for the reading of multiple files .txt in the same times and same script. I have a principal folder Matlab in which there are 7 subfolders Folder1 to Folder 7 in which of them there is un document file.txt.
I would like to read each of 'file.txt' in a script that I run in the curent folder Matlab. is there a fast way to do this? Or am I forced to do load file.txt for each folder.
You can use dir to list all your Folder. Then you can create the path of your file for each folder and load this file.
folder = dir('Folder*'); %list all the folder whose name start with 'Folder'
for ii = 1:length(folder)
s{ii} = fullfile(folder(ii).name,'text.txt'); %create the path for each file
load(s{ii});
end
In a for loop you can create the folder name:
for i = 1:n
name = ['folder',int2str(i)]
% then you can open and read the file
fileID = fopen([name,'\file.txt'])
data = fread(fileID)
% Don't forget to close the file
fclose(fileID)
end

find the path of a file in matlab

Hello I would like to locate the file 'my_file.mat' that should be somewhere inside the folder 'C:\...\mypath\folder1'.
the folder folder1 contains several subfolders and the file my_file could be in any of these subfolders.
I would like to retrieve its full path.
You want to use the which function.
mypath = which('my_file.mat')
As commented below, this assumes that your 'folder1' has been added to your search path. To add (and remove if no longer needed) 'folder1' to your search path:
my_folder_path = 'path/to/folder1'
addpath(genpath(my_folder_path))
mypath = which('my_file.mat')
rmpath(my_folder_path)
I think you are looking for genpath and which combo:
addpath(genpath(folderName));
which test.txt -all
>>
Z:\home\**\Documents\MATLAB\R2010b\bin\test.txt

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?