How to name files in a folder based on parent folder? - matlab

I'm a newbie to Matlab and I got a question regarding naming files in folders. I have 6 folders let's say simulation_data1 to 6, and there are 17 pictures in each folder which are named block_1 to 17 now in all 6 folders. I was wondering how can I name each batch of pictures (17 figs) in every folder based on the name of the parent folder? For example, all figs in folder simulation_data1 become simulation_data1_1 to 17.
any help would be appreciated.
regards

Related

How to move files whose file name is not used in a set of text files?

I'm a Powershell beginner and this is my first post on stackoverflow. I can understand some simple pipelines, but the following challenge is too complicated for me at this point:
I have a folder with testdata containing *.bmp files and their associated files. I want a powershell script to check which bmp-files are still used. If not used, move bmp-files and associated files to another folder.
Details:
bmp-files and associated files: For example; car01.bmp, car01.log, car01.file, car02.bmp, (...)
The bmp-files are in use if their file name (eg, car01.bmp) is mentioned in any of the (text/csv) files in at least one of 2 locations (incl. subfolders).
If the file name is not found in any of the text files, I want the script to move that file, and any file who's name differs only by file extension to a designated folder.
Looking forward to your solutions!

How to read differents folders automatically in matlab? [duplicate]

This question already has answers here:
How to get all files under a specific directory in MATLAB?
(8 answers)
Closed 5 years ago.
I have this folders :
D:/ Houses/objects/*.jpg
D:/ Towers/objects/*.jpg
D:/ Hotels/objects/*.jpg
.
.
.
.
The first folder have different name but inside those folders exists a folder that have the same name (objects) that contain different images in .jpg that i already know how to get them all.
The problem is the first folders have different names , so how can i go over those folders to get the .jpg in matlab, when they have different names and the name donĀ“t have the same prefix either ?
Thank you very much
Use dir
files = dir('D:/*/objects/*.jpg');
fullPath = arrayfun(#(i) fullfile(files(i).folder, files(i).name), (1:length(files))', 'uni', 0);

About FAT-32 File System

I have two questions about FAT-32 file system.
With the FAT-32 File System introduced in wiki, and from the structure provided as following:
,
each file can have name with length no larger than 8?
What's more, I found that the data of the first file I create is as expected to be at cluster #3. (Since root directory begin at cluster #2)
So, does this mean root directory can only store metadata about 16 files? (each occupies 32 bytes in root directory...)
Or, root directory can also get 'fragmented' and each fragments get linked by through information in FAT?
Sorry for my bad formatting.... And thanks for all help.
In FAT-32 a file can have two filenames. One is always an olde-style 8+3 file name. The other optional file name can have up to 255 characters. A system that supports long file names creates a unique 8+3 file name based on the long name. That allowed even older systems that only supported 8+3 file names to access FAT-32 file systems.

MATLAB: How do I copy files with a specific extension to a folder one directory above it?

I am trying to copy specific files from one folder into another folder one directory above it. I want to do this for all of the folders I have at once. Here's my file structure:
201415ContinuousForDropTeqc/StationA/201411/
This path has 25 folders labeled 5 through 30 (representing days).
In each of these 25 folders there are 3 folders named 'dat', 'RAW', 'rinex'.
I want all files ending in .14o from the RAW folder (there are many other file types in this folder as well) to be copied to the rinex folder.
I'm also hoping I can find a way to repeat this for every day in the 201411 folder. This last part isn't critical since I think can type the path manually and just run the script that copy and pastes the files I want.
I hope this was clear. I'm new-ish to MatLab.
Thank you in advance for your help!
Tiffany
You can do all that using the dir command. Check this link.
You can use it twice. first to get all the 25 folders and then to get all the files within the folder.
Days = dir('201415ContinuousForDropTeqc/StationA/201411/');
for k=3:numel(Days) %notice the 3
files = dir([Days(k).name '/RAW/*.14o']);
for n=1:numel(files)
copyfile([Days(k).name '/RAW/' files(n).name],[Days(k).name '/rinex/' files(n).name]);
end
end

How to write relative path in MATLAB?

I need to read a group of dat files so when I do this it is working all right.
list_of_files=dir(fullfile('/home/username/Desktop/Old/MTP/Generate/schemes/o33smnpimp/data/', '*.dat'));
The thing is I want to do this for number of schemes (like o33smnpimp) where every scheme folder has a data folder so I tried something like this but it's not working. What could be the problem?
list_of_files=dir(fullfile('../data/', '*.dat'));
My matlab file lies in o33smnpimp folder.
.. indicates the parent directory, . the current directory. your code looks in /home/username/Desktop/Old/MTP/Generate/schemes/ for the sub directory data, assuming your working directory is /home/username/Desktop/Old/MTP/Generate/schemes/o33smnpimp.
Use
list_of_files=dir(fullfile('./data/', '*.dat'));
or
list_of_files=dir(fullfile('data', '*.dat'));