VB Create Directory
VB Create Directory
VB Create Directory
VB Create Directory
VB Create Directory
VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory
VB Create Directory VB Create Directory
VB Create Directory
Go Back  Xtreme Visual Basic Talk > > > VB Create Directory


Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2010, 10:44 AM
danielair danielair is offline
Newcomer
 
Join Date: Dec 2009
Posts: 9
Default VB Create Directory


Okay I'm trying to create a program that will help manage and organize my music (mp3) files. So I used a ListView (SongList) to show the files that are in my music directory. Then I'm using a class found online to get the Title, Artist, and Album. Then it will insert it into the ListView and assign it a tag with the same value. But then when you hit the button to start the organizing the real problems start. What it is suppose to do is check if the chosen directory exists then if it does it will create a folder for the artist of the song it is processing then a folder for the album then copy and rename (title) the song into that folder, then move onto the next song. But when it tries to create the directory it says there are invalid characters but there aren't. Also for some reason it wont put the Album name into the string for the directory??? Anyway heres the function used to do just about everything:

Code:
Function CopySong(ByVal SongPath As String, ByVal SongName As String, ByVal SongArtist As String, ByVal SongAlbum As String)
        If System.IO.File.Exists(SongPath) = True Then
            Dim RootDir As String = "C:\Users\Caleb\Desktop\Music\"
            Dim DirArtist As String = RootDir & SongArtist & "\"
            Dim DirAlbum As String = DirArtist & "\" & SongAlbum & "\"

            Dim NewSongPath As String = DirAlbum & SongName & ".mp3"

            If My.Computer.FileSystem.DirectoryExists(DirArtist) Then
                If My.Computer.FileSystem.DirectoryExists(DirAlbum) Then
                    MsgBox("1")
                    'System.IO.File.Copy(SongPath, NewSongPath)
                Else
                    My.Computer.FileSystem.CreateDirectory(DirArtist)
                    MsgBox("2")
                    'System.IO.File.Copy(SongPath, NewSongPath)
                End If
            Else
                MsgBox(NewSongPath)
                System.IO.Directory.CreateDirectory(DirAlbum)
                If My.Computer.FileSystem.DirectoryExists(DirAlbum) Then
                    MsgBox("3")
                    'System.IO.File.Copy(SongPath, NewSongPath)
                Else
                    System.IO.Directory.CreateDirectory(DirAlbum)
                    MsgBox("4")
                    'System.IO.File.Copy(SongPath, NewSongPath)
                End If
            End If
        End If
    End Function
Then this is the code used when the start button is pressed:
Code:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        If Not txtSaveTo.Text = "" Then
            Dim i As Integer = 0
            ProgressBar1.Maximum = SongList.Items.Count - 1

            For Each item In SongList.Items
                If SongList.Items.Item(i).Checked = True Then
                    Dim SongPath As String = SongList.Items.Item(i).Tag
                    Dim SongName As String = SongList.Items.Item(i).SubItems.Item(1).Tag
                    Dim SongArtist As String = SongList.Items.Item(i).SubItems.Item(2).Tag
                    Dim SongAlbum As String = SongList.Items.Item(i).SubItems.Item(3).Tag
                    Dim SongGenre As String = SongList.Items.Item(i).SubItems.Item(4).Tag

                    If My.Computer.FileSystem.DirectoryExists(txtSaveTo.Text) = True Then
                        CopySong(SongPath, SongName, SongArtist, SongAlbum)
                        ProgressBar1.Value = i
                    Else
                        My.Computer.FileSystem.CreateDirectory(txtSaveTo.Text)
                        CopySong(SongPath, SongName, SongArtist, SongAlbum)
                        ProgressBar1.Value = i
                    End If
                End If
                i = i + 1
            Next
        End If
    End Sub
Other than that everything works fine. Any help would be awesome

Thanks,
Daniel
Reply With Quote
  #2  
Old 02-23-2010, 11:14 AM
passel's Avatar
passelVB Create Directory passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Perhaps I'm missing something, but it looks like you check if the Artist's directory exist, and if not, you don't create it.

Perhaps if it doesn't exist, you should create the Artist's directory (rather than Album Directory) and things will work better.
And of course, if the Artist's directory was just created, you wouldn't have to check for the sub directories, because they won't exist yet.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 02-23-2010 at 11:20 AM.
Reply With Quote
Reply

Tags
create, directory, function, music, visual basic


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB Create Directory
VB Create Directory
VB Create Directory VB Create Directory
VB Create Directory
VB Create Directory
VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory VB Create Directory
VB Create Directory
VB Create Directory
 
VB Create Directory
VB Create Directory
 
-->