|
|
#1 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
VB - List All The Files In A Directory
This shows the filenames and not the total number of files in a directory.
Last edited by manavo11; Sep 23rd, 2003 at 04:49 PM. |
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Another way (API) :
VB Code:
|
|
|
|
|
|
#3 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
The Dir way :
VB Code:
|
|
|
|
|
|
#4 | |
|
Hyperactive Member
Join Date: May 03
Posts: 358
![]() |
Re: VB - List All The Files In A Directory
Quote:
__________________
The Bloke www.blokeinthekitchen.com making cooking cool for blokes |
|
|
|
|
|
|
#5 | |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: Re: VB - List All The Files In A Directory
Quote:
|
|
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jan 05
Posts: 18
![]() |
Re: VB - List All The Files In A Directory
Yup...this is nice, thank's
|
|
|
|
|
|
#7 |
|
Hyperactive Member
Join Date: Jan 04
Location: Athens (Greece)
Posts: 313
![]() |
Re: VB - List All The Files In A Directory
Nice code example manavo11!
Thanks, i need it!
__________________
Short CV:
My personal web site: http://www.botonakis.com/ My services: http://www.zio.gr/ |
|
|
|
|
|
#8 |
|
Banned
Join Date: Mar 05
Posts: 26
![]() |
Re: VB - List All The Files In A Directory
it works here.
|
|
|
|
|
|
#9 | |
|
New Member
Join Date: Jun 07
Posts: 2
![]() |
Quote:
Hello, Thank for the above code, works a treat but I'm just wondering if anyone could help me out with a similarly easy way to do the same but to list the names of directories ("folders") within a directory? So, the above code works great, it lists all the files of whatever type in say "C:\folder1". What I need is code to list all the directories within "C:\folder1", not including subdirectories. If anyone could help I would be much obliged. Thanks in advance. |
|
|
|
|
|
|
#10 | |
|
Super Moderator
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 54,096
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
Quote:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_DIR = &H18D
Private Const DDL_DIRECTORY = &H10
Private Const DDL_ARCHIVE = &H20
Private Const DDL_EXCLUSIVE = &H8000
Private Sub Command1_Click()
List1.Clear
SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal "C:\folder1\*.*"
End Sub
__________________
Please use [Code]your code goes in here[/Code] tags when posting code. When you have received an answer to your question, please mark it as resolved using the Thread Tools menu. Before posting your question, did you look here? Got a question on Linux? Visit our Linux sister site. I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum. ![]() Creating A Wizard In VB.NET Modifications Required For VB6 Apps To Work On Vista Paging A Recordset What is wrong with using On Error Resume Next Good Article: Language Enhancements In Visual Basic 2010 IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects! Upgrading VB6 Code To VB.NET Microsoft MVP 2005/2006/2007/2008/2009/2010 |
|
|
|
|
|
|
#11 |
|
New Member
Join Date: Jun 07
Posts: 2
![]() |
Re: VB - List All The Files In A Directory
Cool, cheers mate
![]() Had to tweak it a bit of course but working now, thanks. J |
|
|
|
|
|
#12 |
|
Interweb adm/o/distrator
Join Date: Nov 06
Location: Australia, Melbourne
Posts: 2,306
![]() ![]() |
Re: VB - List All The Files In A Directory
Here is my shot it gets all files in sub directories to!
vb Code:
vb Code:
Sorry for the bump.
__________________
If this post was helpful please rate it If it wasn't for C, we would be using BASI, PASAL and OBOL. VB6: [System Uptime] [Extracting WMP Song] [Basic Flood Protection] [RTF Editor] [Hex/String Conversions] [Reading/Writing INI] [List Files in Directories] C++: [Mute Audio in Vista] VB.NET: [Associating a Help File] C#: [One instance of your application] |
|
|
|
|
|
#13 |
|
Lively Member
Join Date: Apr 08
Posts: 74
![]() |
Re: VB - List All The Files In A Directory
just a note that none of the codes work in 2008.
__________________
![]() M.V.B. 2008 Express Edition |
|
|
|
|
|
#14 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
The Visual Studio 2008 you mean? It won't work, it's VB6 code. That's why it's in the VB6 and earlier codebank
|
|
|
|
|
|
#15 |
|
New Member
Join Date: Aug 09
Posts: 1
![]() |
Re: VB - List All The Files In A Directory
[quote=Paul M;2973969]Here is my shot it gets all files in sub directories to!
[quote] Hi Apologies in advance for needing to ask a dumb question, but I'm pretty new to this and flying solo. I'm a tech writer, not a programmer, and have been making a few half-hearted attempts to learn VB so that I can have more control over my word docs. Problem is I am still at the starting blocks and need to catalogue all the template files in a directory, including all sub-dirs, so this post is very interesting to me, but I don't know what to do with the code! I know enough to open the VB editor in word, and paste it into a code window, but I don't know how to name it, or how to call it. Also, there's the question of the sub tacked on at the end and how to deal with it (where does it go, etc). Ok so banish me to the sandpit, but if someone would be kind enough to give me some steps on how to use this code first, I'll be extremely grateful. My other option is to hand type out several thousand file names. (PS While registering for the forum, I noticed an office forum, so i will head over there and read up, but this post is the first one i found covering exactly my required task) |
|
|
|
|
|
#16 |
|
Member
Join Date: Sep 08
Location: Turkey
Posts: 32
![]() |
Re: VB - List All The Files In A Directory
Thanks For aLL!
|
|
|
|
|
|
#17 |
|
New Member
Join Date: Oct 09
Posts: 3
![]() |
Re: VB - List All The Files In A Directory
Hello there, Thanks alot for your code,
just a quick question... is there a way to list files in a directory but get the contents arranged in some ways like "last modified" or "by name" ? |
|
|
|
|
|
#18 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
I'm not sure if there is a way to get the list of files in a specific sorted order. However, since you can get all files, you can then read any information you want for each file (last modified, size, etc) and then do the sorting yourself after you get the whole list!
|
|
|
|
|
|
#19 |
|
New Member
Join Date: Dec 09
Posts: 2
![]() |
Hi I am making a search engine in VB6, your code works but I also need to list all files in subdirs as well. I already searched on google but I couldnt find anything. ( except the ones that cause your whole project to crash:S ) Do you know how to achieve this?
Thanks in advance, Jason Last edited by jason8100; Dec 19th, 2009 at 02:52 PM. Reason: wrong quote |
|
|
|
|
|
#20 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
If you look at this thread: http://www.vbforums.com/showthread.php?t=244880 it's code for listing all sub-directories. If you combine the two, then you have exactly what you want
|
|
|
|
|
|
#21 | |
|
New Member
Join Date: Dec 09
Posts: 2
![]() |
Quote:
Thanks in advance, Jason |
|
|
|
|
|
|
#22 | |
|
New Member
Join Date: Oct 09
Posts: 2
![]() |
Re: VB - List All The Files In A Directory
Quote:
Code:
Dim file As String
file = Dir$("D:\Documents and Settings\Compaq_Owner\My Documents\My Pictures\cards\*.png")
Do While Len(file)
ListBox2.Items.Add(Mid(file, 1, InStr(file, ".") - 1))
file = Dir$()
Loop
|
|
|
|
|
|
|
#23 |
|
Member
Join Date: Nov 09
Posts: 56
![]() |
Re: VB - List All The Files In A Directory
cold we modify this for viewing the images?
|
|
|
|
|
|
#24 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
You could specify an extension. It is mentioned in the examples if you read through them carefully.
|
|
|
|
|
|
#25 | |
|
Member
Join Date: Nov 09
Posts: 56
![]() |
Re: VB - List All The Files In A Directory
Quote:
Dim file As String file = Dir$("D:\Documents and Settings\Compaq_Owner\My Documents\My Pictures\cards\*.png") Do While Len(file) ListBox2.Items.Add(Mid(file, 1, InStr(file, ".") - 1)) file = Dir$() Loop |
|
|
|
|
|
|
#26 |
|
Super Moderator
Join Date: Nov 02
Location: Other side of town from si_the_geek
Posts: 7,153
![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
Try starting with the code from the third post: http://www.vbforums.com/showpost.php...79&postcount=3
It seems like the most similar to the code you have. Compare it, find the differences and I'm sure you'll be able to work it out
|
|
|
|
|
|
#27 |
|
Web developer
Join Date: Dec 01
Location: Adelaide, Australia
Posts: 4,539
![]() ![]() |
Re: VB - List All The Files In A Directory
__________________
My websites My code projects: Backup mysql database 5.3.0 Visual Basic 6.0 Office Outlook mail retrieval Visual Basic 6.0 Client/Server example Visual Basic 6.0 Get number of file in a directory Visual Basic 6.0 Get and Save Ascii Values on keyboard Visual Basic 6.0 Get control name Visual Basic 6.0 Copy application to a different directory Flash Action Script 3 - XML button label VB6.0 - Basic Flash Player Please rate my post if you find it helpful! ![]() I am yet to see a forum without a quote button! If there is I should join it. |
|
|
|
|
|
#28 | |
|
Member
Join Date: Nov 09
Posts: 56
![]() |
Re: VB - List All The Files In A Directory
Quote:
i added a list box named it List1 Error 1 Optional parameters must specify a default value. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 3 74 WindowsApplication1 Error 2 'Public ReadOnly Property Right() As Integer' has no parameters and its return type cannot be indexed. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 7 12 WindowsApplication1 Error 4 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 11 16 WindowsApplication1 Error 5 Type character '$' does not match declared data type 'Integer'. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 11 16 WindowsApplication1 Error 6 'AddItem' is not a member of 'System.Windows.Forms.ListBox'. C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\WindowsApplication1\WindowsApplication1\Form5.vb 17 13 WindowsApplication1 |
|
|
|
|
|
|
#29 |
|
Super Moderator
Join Date: Jul 02
Location: Bristol, UK
Posts: 29,676
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: VB - List All The Files In A Directory
You are getting errors because you are in the wrong place... this is the VB6 Codebank, but you are using VB.Net
Post #22 is the only thing from this thread that you should consider using - for anything else (including help fixing issues with it) you should post in the VB.Net forum.
__________________
Classic VB FAQs (updated Apr 15th) ...Database Development FAQs/Tutorials (updated Mar 29th) (includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial). Tutorial: How to automate Excel from VB6 (or VB5/VBA) .•. SQL 'Select' statement formatter/checker .•. Convert colour number to colour name .•. FlexGrid: fill from recordset .•. FlexGrid: AutoSize columns .•. DB Reserved Words checker Connection strings .•. MDAC/Jet/ACE downloads .•. SQL Server downloads .•. MZTools (free upgrade for the VB6/VBA Editor) |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|