sort by id in filename it is possible?

Hi,

I have some audio files in my directory. This files haves in title 4 chaaracters id.
Example: the_doors_5541.mp3, prodigy_5541.mp3 and I want sort my files by id.
How can I do this, any ideas ?

The easiest way is to but the id first.

The easiest way would be to index the files in a database, but using what you have:

Start out by picking apart the file name parts.

  1. Remove the extension
  2. Explode the string using the separators.
  3. Custom sort using the numbers.

However, that is a lot of work just to find a file by number. Indexing them in a database is far better and allows for growth potential.

– AND NO, I do not have sample code for you to use –

Thanks all, so it’s not easy because i don’t wanna use for this mysql .

Get a software called Better File Rename and batch rename the files.

Sukisuki,

Nobody said it was hard, just that there was better ways. Astonecipher gave you the 3 simple steps to
handle this… I will add to his list for you…

  1. to remove the extension, just take the string and drop the last four character. Or, when you read
    the filenames of the music files, do not include the extensions. Read up on filename and directories.
    ( You can use stringpos() function to find where it is or use the string len function to
    locate the size and then just use the substr() function to strip out the value without the ext.)

  2. use the explode() function to create an array of words in the string using the underscore “_” as
    the character to explode on. Use count() to get the number of words in the array and then that
    index should point at the number.

  3. Since you did not have the number at the beginning, you might want to rebuild the string back
    into two entries, one with the number and one with the other words combined back into the title.
    ( OR, better, rewrite all the names so they start with the number ID so that the filenames can be
    easier to sort.)

Remember ANYTHING can be done in programming, but, some ways are much easier. Databases are really
created for things like this and makes life easier when displaying the data, searching it and sorting it. But,
it can be done easily enough if you just think it out further.

Hope this helps… Oh, here is a link to most all of the string functions so that you can look at how they
all work. Might help a bit… http://www.w3schools.com/php/php_ref_string.asp

Sponsor our Newsletter | Privacy Policy | Terms of Service