|
-
Aug 1st, 2010, 08:27 PM
#1
Thread Starter
Junior Member
[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
-
Aug 1st, 2010, 08:35 PM
#2
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.
-
Aug 2nd, 2010, 08:09 PM
#3
Thread Starter
Junior Member
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
-
Aug 2nd, 2010, 08:13 PM
#4
Re: Drag and Drop - Folder
That is the default behaviour but Directory.GetFiles allows you to specify either option.
-
Aug 2nd, 2010, 10:48 PM
#5
Thread Starter
Junior Member
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
-
Aug 2nd, 2010, 11:04 PM
#6
Re: Drag and Drop - Folder
Read the MSDN documentation for the DirectoryInfo.GetFiles method. All you need is in there.
-
Aug 4th, 2010, 08:24 PM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|