Create multiple nested subfolders and paste files with different specifications

Dear all

Let's imagine the following scenario. In a cluster, I have a folder named "/work/projectnumber/projectnumber/user/CrSBr". In this folder, I have different subfolders. The relevant ones for this case are called "Input-Files", "ucf-Files", and "mat-Files":

(i) Within "Input-Files", the following subfolders exist (each new line implies that the folders cited are within the above one):

  • “Zero-Field-Cooling”, “Field-Cooling”, ", "Artificial-Domain-Wall", "Time-Series", "Inverse-Zero-Field-Cooling", "Inverse-Field-Cooling";
  • “Monolayer”, “Multilayer”;

and in each of them there is a file named “input” with different specifications.

(ii) Within "ucf-Files", the following subfolders exist (each new line implies that the folders cited are within the above one):

  • “Monolayer”, “Multilayer”;
  • “Scaled-DMI”, “Unscaled-DMI”;
  • “D3-D1-1”, “D3-D1-1with2”, “D3-D1-1with4”, “D3-D1-1with6”, “D3-D1-1with8”, “D3-D1-2”, “D3-D1-2with2”, “D3-D1-2with4”, “D3-D1-2with6”, “D3-D1-2with8”, “D3-D1-3”;

within these subfolders, there is a single file named "CrSBr-Monolayer-Unscaled-DMI-D3-D1-1.ucf" for the "ucf-Files/Monolayer/Unscaled-DMI/D3-D1-1" case and "CrSBr-Multilayer-Scaled-DMI-D3-D1-1with4.ucf" for the "ucf-Files/Multilayer/Scaled-DMI/D3-D1-1with4" case, to give two examples.

(iii) Finally, inside the "mat-Files", the following subfolders exist (each new line implies that the folders cited are within the above one):

  • "Monolayer", "Multilayer";
  • "Domain-Wall", "No-Domain-Wall";

within these last subfolders, there is a single file called "CrSBr-Monolayer-No-DW.mat" for the "mat-Files/Monolayer/No-Domain-Wall" case and "CrSBr-Multilayer-DW.mat" for the "mat-Files/Multilayer/Domain-Wall" case, to give two examples.

Now, let’s imagine that I want to create the following sequence of folders within the "CrSBr" for the case of simulations related to the "Input-Files/Field-Cooling". First, in "CrSBr", I want to create a folder called "Field-Cooling". Within "Field-Cooling", the following subfolders (each new line implies that the folders cited are within the above):

(i) "Monolayer", "Bilayer", "Trilayer";

(ii) "Rectangular-Sample", "Square-Sample";

(iii) "0-K", "2-K";

(iv) "Dipolar-Hierarchical", "Dipolar-Tensorial";

(v) "Scaled-DMI", "Unscaled-DMI";

(vi) "D3-D1-1", "D3-D1-1with2", "D3-D1-1with4", "D3-D1-1with6", "D3-D1-1with8", "D3-D1-2", "D3-D1-2with2", "D3-D1-2with4", "D3-D1-2with6", "D3-D1-2with8", "D3-D1-3".

In each of the folders in (vi), I need to paste the “input” file and two files named “vampire-parallel” and “CrSBr-Field-Cooling.slurm” (the latter two being in “CrSBr”. However, I need to change some parts of the “input” and “CrSBr-Field-Cooling.slurm” files depending on which folder path they will be placed in. So, for “input”:

(i) if the folder path contains “Rectangular-Sample”, I need the line “dimensions:system-size-x = x !nm” to become “dimensions:system-size-x = 200.0 !nm” and “dimensions:system-size-y = x !nm” to become “dimensions:system-size-y = 50.0 !nm”. If it is in “Square-Sample”, “dimensions:system-size-x = 100 !nm” and “dimensions:system-size-y = 100 !nm”.

(ii) If the folder path refers to “Bilayer”, I need the line “dimensions:system-size-z = x !nm” to become “dimensions:system-size-z = 1.62 !nm”, while if it refers to “Trilayer”, that line should become “dimensions:system-size-z = 2.43 !nm”. For both “Bilayer” and “Trilayer”, the “input” file comes from the “CrSBr/Input-Files/Multilayer” path.

(iii) Regardless of whether the case corresponds to “Monolayer” or “Multilayer”, I need to change the line “material:unit-cell-file = CrSBr-x.ucf” with the name corresponding to the final folder path where it will be hosted. For example, if the final folder is “CrSBr/Field-Cooling/Bilayer/Rectangular-Sample/0-K/Dipolar-Hierarchical/Scaled-DMI/D3-D1-1”, “material:unit-cell-file = CrSBr-Multilayer-Scaled-DMI-D3-D1-1.ucf”.

(iv) In this case “Field-Cooling”, as far as the “mat-Files” file is concerned, is of category “No-Domain-Wall”, so the line “material:file = CrSBr-x.mat” should be “material:file = CrSBr-Monolayer-No-DW.mat”/“material:file = CrSBr-Multilayer-No-DW.mat”.

(v) If the folder path contains “0-K”, I have to replace the line “sim:minimum-temperature = x” with “sim:minimum-temperature = 0.0”, and if it is in “2-K”, with “sim:minimum-temperature = 2.0”.

(vi) If the folder path contains “Dipolar-Hierarchical”, I have to replace the line “dipole:solver = x” with “dipole:solver = hiearchical” and with “dipole:solver = tensor” for “Dipolar-Tensorial”.

On the other hand, regarding “CrSBr-Field-Cooling.slurm”, I only need to change the line “#SBATCH --job-name=CrSBr-x” to “#SBATCH --job-name=CrSBr-1L-FC” for “Monolayer”, “#SBATCH --job-name=CrSBr-2L-FC” for “Bilayer”, and “#SBATCH --job-name=CrSBr-3L-FC” for “Trilayer”.

I have previously posted about related topics in this forum (sorry, I cannot link them since I am considered a new user). There are really good answers there, but I am still trying my best to understand them completely.

There you go:

And so far, how is it going for you? :slight_smile:
Maybe reading this section of Bash manual can shed some light on how "brace expansion" mechanism works, and a longer one about parameter expansion.

On the command line, test the brace expansion with echo:

echo {aa,bb,cc}
echo {0..9}
echo {00..09..2}
echo {a,b,c}/{0..2}
echo {a,b/{0..2},c}
...