Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I've been looking for answer on the web now for a few hours and can't find what im looking for. What i want to do is move each file in a directory to a new folder using the name of the file, excluding the extension.

/Movies/Filname.avi ---> /Movies/Filename/Filename.avi

I know how to do each individual file, but can i do it reclusively for the whole folder using one command or a script.

share|improve this question
    
Can you please post your script as an answer instead of adding it to the question? Would make it easier to other users to understand what's going on. –  patrix Feb 18 at 8:57

1 Answer 1

This should do the trick.

#!/bin/bash
shopt -s nullglob    #avoid problems in directory with no files
ext=avi              #the file extension to search for
for f in *.$ext; do
    d="${f##/}"      #gives us just the filename
    d="${d%.$ext}"   #strips the file extension
    mkdir "$d"       #makes the directory
    mv "$f" "$d/$f"  #moves the file
done
share|improve this answer
    
In the end I decided to write my own, not bad only that i have multiple extensions. I'll post my script in a few hours, when I am allowed –  moosethemucha Feb 18 at 6:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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