Results 1 to 7 of 7

Thread: [RESOLVED] Drag and Drop - Folder

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Resolved [RESOLVED] Drag and Drop - Folder

    Hello Everyone,

    I have been able to implement drag and drop successfully on my listView object if you were to drop a file on it, however I seem to be having some troubles if the user were to drag the folder onto the object. Is there a simple way to check if the user dropped a folder, and if so, list all of the files in the folder/subfolders?

    Thanks in advance!
    noop

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Drag and Drop - Folder

    I haven't tested dropping a folder but I would expect that you would get a path in a FileDrop just as you do for a file. You can use the IO.File.Exists and/or the IO.Directory.Exists method to determine whether you have a file path or a folder path. If you have a folder path, the IO.Directory.GetFiles method will give you all the file paths. Just note that, if the folder contains subfolders, you may need to use IO.Directory.GetDirectories recursively to get files at all levels.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Re: Drag and Drop - Folder

    Ok, I am able to determine whether or not the user dropped a folder or file, but now it seems like it is only reading the files in that one folder, rather than read all of the files in the folder as well as its subfolders.

    Thanks for helping me with this,
    noop

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Drag and Drop - Folder

    That is the default behaviour but Directory.GetFiles allows you to specify either option.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Re: Drag and Drop - Folder

    Here is what I am using... How do you use GetFiles to work recursively throughout the sub folders?

    Code:
    For Each file_name As String In file_names
                If IO.Directory.Exists(file_name) Then
    
                    ' make a reference to a directory
                    Dim ioDir As New IO.DirectoryInfo(file_name)
                    Dim dir1 As IO.FileInfo() = ioDir.GetFiles("*.txt")
                    Dim subFile As IO.FileInfo
    
                    For Each subFile In dir1
    
                        Me.lstAddMedia.Items.Add(subFile.FullName)
                        Me.lstAddMedia.Items.Item(files).SubItems.Add("Extra Column")
                        files += 1
                    Next
    
                ElseIf IO.File.Exists(file_name) Then
                    If IO.Path.GetExtension(file_name) = ".txt" Then
                        Me.lstAddMedia.Items.Add(file_name)                  
                        Me.lstAddMedia.Items.Item(files).SubItems.Add("Extra Column")
                        files += 1
                    End If
                End If
            Next file_name
    Thank you for helping,
    noop

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Drag and Drop - Folder

    Read the MSDN documentation for the DirectoryInfo.GetFiles method. All you need is in there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Re: Drag and Drop - Folder

    Wow, I feel stupid I didn't see that.

    Thanks again!

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