Score:2

How can you create multiple folders with names that are altered versions of the names of existing files?

je flag

I have approximately 100 files with the file names such as: "1999 - Film Title.avi" & "2025 - Another Film Title.avi", etc. I would like each of these files to be moved to an individual folder with the folder name formatted like these examples: "Film Title (1999)" & "Another Film Title (2025)". Is such a thing possible, or will this be a laborious manual task?

I am using Ubuntu server (Ubuntu 22.04.2 LTS).

thank you

Score:2
jp flag

In bash ... Try this for a dry-run:

for f in *.avi
  do
    # Get the name part
    n="${f:7}"
    n="${n%%\.*}"
    # Get the year part
    y="${f:0:4}"
    # Define directory name
    d="${n} (${y})"
    # Create directory
    echo mkdir -pv -- "$d"
    # Move file into directory
    echo mv -nv -- "$f" "${d}/"
    done

If, the output sounds like what you want, then run this to do it for real:

for f in *.avi
  do
    n="${f:7}"
    n="${n%%\.*}"
    y="${f:0:4}"
    d="${n} (${y})"
    mkdir -pv -- "$d"
    mv -nv -- "$f" "${d}/"
    done
Diffusive9076 avatar
je flag
Wow. Thanks Raffa. It worked very well!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.