0

A large number of font files (2728 files) are flattened in to a single folder.

I want to move all files belonging to the same font family into a folder where the folder name is the complete name of the font family.

For example in the following list of files:

Axle.otf
AxleBold.otf
AxleBoldItalic.otf
AxleCondBold.otf
AxleCondensed.otf
AxleCondItalic.otf
AxleExpanded.otf
AxleExpBold.otf
AxleExpItalic.otf
AxleItalic.otf
AxleNarBold.otf
AxleNarItalic.otf
AxleNarrow.otf
AxleWide.otf
AxleWideBold.otf
AxleWideItalic.otf

Distract.otf
DistractBold.otf
DistractBoldItalic.otf
DistractCondBold.otf
DistractCondensed.otf
DistractCondItalic.otf
DistractExpanded.otf
DistractExpBold.otf
DistractExpItalic.otf
DistractItalic.otf
DistractNarBold.otf
DistractNarItalic.otf
DistractNarrow.otf
DistractWide.otf
DistractWideBold.otf
DistractWideItalic.otf

Voltagio.otf
VoltagioBold.otf
VoltagioBoldItalic.otf
VoltagioCondBold.otf
VoltagioCondensed.otf
VoltagioCondItalic.otf
VoltagioExpanded.otf
VoltagioExpBold.otf
VoltagioExpItalic.otf
VoltagioItalic.otf
VoltagioNarBold.otf
VoltagioNarItalic.otf
VoltagioNarrow.otf
VoltagioOutline.otf
VoltagioWide.otf
VoltagioWideBold.otf
VoltagioWideItalic.otf

I want all the files that start with “Axle” to be in one folder named Axle; those that start with “Distract" to be in a folder named Distract; all “Voltagio" files to move a Voltagio folder, etc.

Basically, the shortest name of a font file is the base name of that font family and should be used to collect the family into a folder with that base name. The base name varies in length from about 4 to 12 characters.

Another issue is that some “families” consist of only one file and so I don’t want those to go into a separate folder but to remain at the root level of the destination folder.

Any help would be appreciated.

0

In your example, I see that all your files named <font-family>[<style-surfix>].otf:

  • <font-family> appears in all of filenames, also are all font-family directories which you want to create
  • <style-surfix> could be one, or combination of 7-element set: Bold, Italic, Cond, Exp, Nar, Wide, Out

In order to present my answer more easily, I call:

  • <font-family>.otf: bare font
  • <font-family><style-surfix>.otf: derived font

This script does your task correctly:

# move all `derived fonts` to `.temp/` directory:
mkdir -p .temp/
mv "*{Bold,Italic,Cond,Exp,Nar,Wide,Out}*.otf" .temp/ 2> /dev/null

for file in ./*.otf; do
    # get `family name` based on `bare font`'s name
    name=${file%.*}

    # create `family directory`
    mkdir -p "${file%.*}"

    # move `bare font` to correct directory
    mv "$file" "$name/"

    # move `derived font` to corresponding `family directory`
    mv .temp/"$name"*.otf "$name/"
done;

# remove temporary directory
rmdir .temp/ 2> /dev/null
| improve this answer | |
  • My script works with your example correctly. If it doesn't work with your 2728 files, please don't hesitate to comment below. – ne3suszr Nov 11 '19 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.