Page 1 of 1

Reading and editing filenames

Posted: Sat Mar 05, 2011 2:50 pm
by mattthac
Here's the background of what i want to do, I have a music folder that contains all of the groups of music that I have either ripped from my cd's or downloaded over many many years of being online. inside the main music folder is a folder for each music group and within that is folders for each cd, sometimes this goes deeper depending on the group sometimes 3-4 levels deep here's an example

D:\Music\3 Doors Down\(2000) Kryptonite
D:\Music\Dave\Live Trax Series 1-16\Live Trax Vol. 1 (Worcester, MA 12.8.1998)\Disc 1

as you can see some go deeper than others.

Now what I'm wanting to do is to be able to loop through a selected groups folder, lets say 3 doors down and remove extra chars from the filenames such as the following:
all of the files in my 3 Doors Down folder have the following filename structure

3 Doors Down - Kryptonite.mp3

What I want to do is be able to remove the "3 Doors Down - " part from the name so when i burn mp3 cd's the titles are just the actual song name.
Some of the filenames have the extra chars at the front some at the back. What would be the best way to cycle through and remove the unwanted chars.

Other example:
07. Any Colour You Like - Pink Floyd.mp3

Would like to be able to remove the " - Pink Floyd" from the end in this case.

I basically just want to strip the artists name off of the songs. It would be awesome if i had a page that i could input the directory to run on and input the chars I want to remove

for the pink floyd example

Have input boxes that allow me to input the directory as D:\Music\Pink Floyd
then a box that allows me to input chars to remove " - Pink Floyd"
if needed i guess a selection box to select front or back of the filename to remove the chars entered above.

This sounds kind of weird but I have like 15000 songs and really don't want to manually have to remove this stuff.

Any help would be greatly appreciated, its been several years since I've coded in php and am very rusty

Re: Reading and editing filenames

Posted: Sat Mar 05, 2011 5:36 pm
by Christopher
To loop through the directories you could use a combination of glob() and the is_dir() functions (there are lots of filesystem functions to help you with this):
http://us2.php.net/manual/en/function.glob.php
http://us2.php.net/manual/en/function.is-dir.php

Another option are the SPL classes for this:
http://us2.php.net/manual/en/class.dire ... erator.php
http://us2.php.net/manual/en/class.recu ... erator.php