Sign in to follow this  
Followers 0
Guest IceBlue

Handling Of Directory And File Names

5 posts in this topic

Hello folks,

' couple of days ago I was looking for a relatively easy to learn programming language - but mighty enough for my purposes . Then I found AutoIt and was fascinated by the extensive features.

The option to compile own scripts, create gui and the fact that it is free convinced me!

Then I decided to start my first project, and ... now I'm stuck before I wrote the first line :lol::ph34r::( .. oops ..

I want to write a script that supports me in several different complex music encoding tasks including conversion to flac (lossless), mp3, ogg vorbis, tagging, generating md5 checksums, generating par2 files (for the safety), automatic downloading cover arts, muxing the flac files with cover art and cue files into matroska container.... and finally having everything in the appropriate place. The backends for all these single tasks are existing.

When I rip my music CD's, I do five or more before conversion. The ripper places the wav files into a certain structure .... for example d:\fresh rips\genre\artist\year - album\[track #] title.wav or (mainly for live albums) d:\fresh rips\genre\artist\year - album\album.wav as one big file plus cue sheet.

What I want to do is to point the script to d:\fresh rips and want it to proceed all the files in the different subfolders one by one and analyze the structure and the filenames to pass them to the tagger... etc. and then place the encoded files into different main folders with the same structure behind. After conversion d:\fresh rips\ is empty.

O.K. what's my problem....

1. How can I extract $genre, $artist, $year, $album, $track and $title (how to separate $year from $album)?

2. How to force the script to take all the files ?

The first step will be a static script. If I succeed I'm planning to generate a config file with the script to become more flexible.

Maybe s.o. can point me into the right direction please.

As you can see, this is my first post. Hope these questions are not too stupid.

So please be merciful with a rookie :iamstupid:

THX

Share this post


Link to post
Share on other sites



Hello folks,

When I rip my music CD's, I do five or more before conversion. The ripper places the wav files into a certain structure .... for example d:\fresh rips\genre\artist\year - album\[track #] title.wav or (mainly for live albums) d:\fresh rips\genre\artist\year - album\album.wav as one big file plus cue sheet.

What I want to do is to point the script to d:\fresh rips and want it to proceed all the files in the different subfolders one by one and analyze the structure and the filenames to pass them to the tagger... etc. and then place the encoded files into different main folders with the same structure behind. After conversion d:\fresh rips\ is empty.

O.K. what's my problem....

1. How can I extract $genre, $artist, $year, $album, $track and $title (how to separate $year from $album)?

Since they're each in different subfolders and you have the name of the files available a filename will look like this:

D:\fresh rips\jazz\jambo\2004 - some club\album.wav.

You can now just use StringSplit() to get each part. If you StringSplit at the \ character you'll have:

D:

fresh rips

jazz

jambo

2004 - some club

album.wav

You then just have to use StringLeft to get the year and then remove the first 7 characters from "2004 - some club" which will give you the name of the album.

2. How to force the script to take all the files ?

If you want to process all files in the folder just let the script find the files itself... you'll just need the two FileFind* commands and put a loop around this.

The first step will be a static script. If I succeed I'm planning to generate a config file with the script to become more flexible.

This will be very easy. Just be sure to use only variables (so for testing you set $SourceDir = 'd:\fresh rips' and never use anything different than $SourceDir when reffering to this folder. Then you'll just have to throw in a IniRead (or RegRead if you prefer the registry).

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

As long as you keep the structure the same, it shouldn't be a problem.

d:\fresh rips\genre\artist\year - album\[track #] title.wav

Ok, first you can look in the d:\fresh rips to get each $genre.

Then get all the artists into $artist, and do the same for year_album.

And finally grab your wav files.

here is a quick example, but I think I would actually just parse out a dos directory dump myself. but here ya go.

$dir="d:\fresh rips\"
$g=getsubs($dir & "*.")
$genre=StringSplit($g,"|")

For $g=1 To $genre[0]
$artist=StringSplit(getsubs($dir & $genre[$g] & "\*."),"|")
For $a=1 To $artist[0]
$year_album=StringSplit(getsubs($dir & $genre[$g] &"\"& $artist[$a] &"\*."),"|")
For $y=1 To $year_album[0]
MsgBox(1,$genre[$g],$artist[$a] & @CRLF & $year_album[$y])
Next
Next
Next


Func getsubs($path)
    $search=FileFindFirstFile ($path) 
For $i=1 To 10
$x=FileFindNextFile ($search) 
If $x="." or $x=".." Then ContinueLoop
    If $x="" Then ExitLoop
$y=$y&"|"& $x
Next
$y=StringTrimLeft($y,1)
    Return $y
EndFunc

I left you to grab your own files from each of the directories.

The other way might be just to use dos to dump the contents of the d:\fresh rips\ and parse that.

side note, once you figure out the format year-album has, you can do a

dim $year[ubound($yearalbum)]

dim $album[ubound($yearalbum)]

$year[$y]=StringLeft($year_album[$y],4)

$album[$y]=StringTrimLeft($year_album[$y],5)

or something like that.

Anyway just showing one crazy approach....

Dos Dump Code

runwait(@comspec &' /c "d:\fresh rips\*.wav" /s >mysongs.txt')
; you might have to use runwait(@comspec &' /c "d:\freshr~1\*.wav" /s >mysongs.txt')
; parse the file, and everytime you see directory of in the front, use this line to get artist, year, genre, etc.
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Thanks sugi that are good points for my start!

@scriptkitty

wow, I obtained more help than I could hope! Thanks for the code :ph34r:

I think you saved me a lot of time :( .

I tried the dos directory dump, but didn't work in the beginning. The file was created, but it was empty.

CODE

runwait(@comspec &' /c "d:\fresh rips\*.wav" /s >mysongs.txt')

; you might have to use runwait(@comspec &' /c "d:\freshr~1\*.wav" /s >mysongs.txt')

; parse the file, and everytime you see directory of in the front, use this line to get artist, year, genre, etc.

After playing a bit I figured out that the quotes must close on another position

runwait(@comspec &' /c "d:\fresh rips"\*.wav /s/b >mysongs.txt')

Does it now...! :lol:

Thanks again

Share this post


Link to post
Share on other sites

oops, I forgot to dump the directory, lol

DIR was missing

runwait(@comspec &' /c dir "d:\fresh rips\*.wav"  /s >mysongs.txt')

Thanks sugi that are good points for my start!

@scriptkitty

wow, I obtained more help than I could hope! Thanks for the code  :ph34r:

I think you saved me a lot of  time  :(  .

I tried the dos directory dump, but didn't work in the beginning. The file was created, but it was empty.

After playing a bit I figured out that the quotes must close on another position

runwait(@comspec &' /c "d:\fresh rips"\*.wav /s/b >mysongs.txt')

Does it now...!  :lol:

Thanks again

<{POST_SNAPBACK}>


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0