Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2010, 07:15 AM
Registered User
 
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..
 
Old August 27th, 2010, 07:02 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old August 27th, 2010, 07:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old August 28th, 2010, 02:49 AM
Registered User
 
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
 
Old August 28th, 2010, 04:01 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
The Following User Says Thank You to Imar For This Useful Post:
kumar.selva.c (September 1st, 2010)
 
Old September 1st, 2010, 06:14 AM
Registered User
 
Join Date: Aug 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Files and Folders

Thanks Imar
 
Old September 26th, 2011, 12:58 PM
Registered User
 
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”)





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 01: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.