Results 1 to 12 of 12

Thread: for next problem [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    for next problem [RESOLVED]

    why doesn't this work?

    Code:
    dim filename as new file
    for each filename
      'i send it to a subroutine to extract info
    next filename
    what do I need to do to successfully search through an unknown # of mp3 filenames( I have over 10,000) and send each filename to my subroutine (as a string variable called fileName) to split it up (I have the code written to split it up for artist, album, so forth)?
    Last edited by Andy; Dec 29th, 2003 at 03:22 AM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    You need to specify a folder...For each file in folder...
    VB Code:
    1. Dim folderName As New Folder
    2. Dim filename as new file
    3.  
    4. folderName = 'path to folder
    5.  
    6. For each filename in folderName
    7.    'Add mp3 names to listbox
    8.    Listbox1.Items.Add(filename.Name (or whatever it is)
    9. Next
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    the keyword "folder" doesn't work in vs 2003 or something. Is there a namespace I need to import?

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    use directory instead of folder.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok ok...I tried that and it liked that much better. Do I have to imports namespaces in the modules AS WELL as my forms class? Or do i simply need to imports them in one or the other?

    Code:
    Sub SegregateFile()
            'this routine will take the file apart and give us ARTIST ALBUM TRACK# AND TRACKNAME
            'since the filename is a strict format, this has been written around that format only.
    
            Dim folderName As New Directory
            Dim MP3 As New File
    
            For Each filename In folderName
                Dim intCount As Integer = 0
                For intCount = 0 To 6 Step 2
                    Dim array() As String = Split(filename) 'this statement will break up the full path
                    array(0) = Mid(array(0), 4) 'this statement will take off the x:\ at the beginning
                    Console.WriteLine(array(intCount)) 'testing purposes only, erase when done
                    'this will be replaced with a statement to assign the results to parent and child tree nodes
                Next intCount
            Next MP3
        End Sub
    what isn't working now are these errors: 'System.IO.Directory.Private Sub New()' is not accessible in this context because it is 'Private'. from the dim foldername as directory statement

    'System.IO.File.Private Sub New()' is not accessible in this context because it is 'Private'. from the dim mp3 statement
    and:

    Name 'filename' is not declared. from the for each filename statement.

    any ideas why i'm getting these errors? I assume it's something to do with not importing the right namespaces.

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    First do this to import IO Namespace
    Imports System.IO

    Change this :

    VB Code:
    1. Dim folderName As New Directory
    to
    VB Code:
    1. Dim folderName As Directory

    Secondly , 'filename' is not declared , declare it first .

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    well, that worked, Pirate, but it turns out that's not what I was after. arrgh!

    I'm going to start from a clean slate with this project. The simple fact I can't figure it out is making want to complete it even more. I did find some sample code in the msdn to list all files in a directory, good start. Now, I need to work through how to extract the text BETWEEN the dashes. My code earlier actually skipped every other word but that was WAY wrong. I think the indexof() may be the key here.

    If anyone has any ideas on this, trust me, I'd be SO grateful. I can't believe a simple project like this is kicking my butt.

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I'm not sure exactly what you mean by extracting the text between dashes . Do you want to get the file name only or the folder or just some kewords . Here , you got to use Split Function in the String object .

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    yeah, I tried the split function problem is, I can't think of how to store what I need.

    The first obstacle is to abe able to get mp3's from multiple sub-folders. I don't have all of them in just one and I'd like to be able to get the app to search for me. (they are on one drive however).

    for example:

    z:\van halen - ou812 - 08 - black and blue.mp3

    what I need to do is get "van Halen" and that's gonna be my parent node (artist) for a tree control, get "ou812" for a child node (album) and then "black and blue.mp3" will need to be dislplayed in the child node (as the file).

    what I'm having the most trouble with is being able to get text from between the dashes (that's the key seperator). the text has spaces sometimes and it makes it difficult to use the split() function. Thats why, at first, i was trying to use the instr() and mid().

    Can you suggest any better ideas?

  10. #10
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    as Memnoch1207 was saying And Pirate also , if you look at the Directory namespace.
    you can do allsorts with a bit of experimenting with the code, eg:
    VB Code:
    1. Dim f As New IO.FileInfo("C:\30 Led Zeppelin - The Very Best Of\CD1 Early Days\05 - Whole Lotta Love.mp3")
    2.         Dim track As String = f.Name.Replace(f.Extension, "")
    3.         Dim artist As String = f.Directory.FullName.Substring(3) '/// get rid of the drive letter.
    4.         Console.WriteLine(artist & Environment.NewLine & track)
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Or even shorter ...
    VB Code:
    1. Dim f As New IO.FileInfo("C:\30 Led Zeppelin - The Very Best Of\CD1 Early Days\05 - Whole Lotta Love.mp3")
    2.         For Each s As String In f.FullName.Split("\".ToCharArray)
    3.             MsgBox(s)
    4.         Next

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    hey sysop, is this what output you get when you run that code?

    C:
    30 Led Zeppelin - The Very Best Of
    CD1 Early Days
    05 - Whole Lotta Love.mp3

    That's what I got anyway.

    I walked through it and can't understand how it comes up with what it does. could you give a brief run-down of the code?

    I read up on the fileinfo namespace and DID find the properties and methods you suggested and DO understand them.

    I didn't seem to find the members you used when I looked up the directory namespace. I'm so new to namespaces and classes and such, I am having a hard time using the msdn to find anything.

    i'm trying though!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width