Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2008 Professionals For advanced Visual Basic coders working in version 2008. Beginning-level questions will be redirected to other forums,
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 26th, 2010, 07:15 AM
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Cool Files and Folders in VB.Net2008

Hi,

I'm new to VB.Net, i have a situation like,you have folder name "Arrange", inside this, it contains so many "txt" and "zip" files, you can rearrange it by right clicking and select "Arrange By , Last modified", i have to access this option through code and have to do this every time while i'm looping or entry of the function.

I can do this in program through forEach loop and get details like filename and creationDate, but i want to arrange it in "Arrange" Folder.

Please help me out.

Thanks in Advance:-)

Last edited by kumar.selva.c; August 27th, 2010 at 05:41 AM.
Reply With Quote
  #2 (permalink)  
Old August 27th, 2010, 07:02 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Hi there,

You can use a combination of DirectoryInfo and LINQ to get files from the file system and group them by something, such as a file extension. Here's a quick example that lists all files in a folder, each file grouped under an Extension header:

Code:
 
Dim folder As String = "C:\SomePath"
Dim directoryInfo As New IO.DirectoryInfo(folder)
 
Dim allFiles = From f In directoryInfo.GetFiles() _
      Group f By Extension = f.Extension Into Group _
      Select Extension = Extension, Files = Group
 
For Each fileGroup In allFiles
  ' Write out the extension for the group
  Console.WriteLine(fileGroup.Extension)
  For Each file In fileGroup.Files
    ' Write out each individual file name in the group
    Console.WriteLine("  " & file.Name)
  Next
Next
For more information about this, check out the System.IO namespace and the 101 LINQ examples: http://msdn.microsoft.com/en-us/vbasic/bb688088.aspx

You can do similar stuff for other groups, like date created, first letter of the filename and so on.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old August 27th, 2010, 07:04 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

BTW, the output of this code will be something like this:

Code:
 
.docx
  SomeFile1.docx
  SomeFile2.docx
.txt
  SomeFile1.txt
  SomeFile2.txt
  SomeFile3.txt
.zip
  SomeFile1.zip
  SomeFile2.zip
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #4 (permalink)  
Old August 28th, 2010, 02:49 AM
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Cool Files and Folders

Hi Imar,

Thanks for your kind reply, and mine is little bit different situation,

see, jus create a folder named "Arrange" or wat eve u like, and put some "txt" and "zip" files with different creation time of each file.

Do right click and select arrange by lastmodified, so that all files will be arranged by creation date and Time. This is the folder option.

I want to access this option through coding, so that i can aovid so many lines of coding.

could u plz help me out this?

Thanks in advance.

Regards,
Selva
Reply With Quote
  #5 (permalink)  
Old August 28th, 2010, 04:01 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Hi there,

I am not sure what you're asking. This is a Windows UI feature, so how would you access this through code? If this is about a UI and selecting files, you can use an OpenFileDialog which supports this by default.

Otherwise, I think you need to code it yourself.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
kumar.selva.c (September 1st, 2010)
  #6 (permalink)  
Old September 1st, 2010, 06:14 AM
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Files and Folders

Thanks Imar
Reply With Quote
  #7 (permalink)  
Old September 26th, 2011, 12:58 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default List Files in a Directory

List Files in a Directory
A little code snippet that lists files in a directory.
Quote:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim di As New IO.DirectoryInfo("c:\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo

'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
To filter search change di.GetFiles() to di.GetFiles(“.extionsion”)
Reply With Quote
Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Authenticating Specific Files and Folders homepagestore BOOK: Professional ASP.NET 3.5 SP1 Edition: In C# and VB 2 December 13th, 2009 12:50 AM
compress a set of files and folders prathapkumar ASP.NET 3.5 Basics 1 September 11th, 2009 04:48 AM
connect to files from different folders lcyean ASP.NET 2.0 Basics 1 May 11th, 2007 07:23 AM
Check For Existing Folders & Files zandermax Access VBA 2 September 30th, 2005 11:43 AM
Including files across folders dsunmedia Beginning PHP 3 July 26th, 2004 04:17 PM



All times are GMT -4. The time now is 08:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.