-
Drive Listing in VB.NET
Hi..
I am making a Windows Application in VB.NET and I
am missing the dirlistbox and the drivelistbox.
What classes to use to get all physical drives etc ???
Thanks,
- Vikram
vikram_s@mailandnews.com
-
Re: Drive Listing in VB.NET
Vikram,
> What classes to use to get all physical drives etc ???
Dim p_astrDrives as Array
Dim p_astrDirs as Array
Dim p_astrFiles as Array
p_astrDrives = System.Environment.GetLogicalDrives()
' where p_strSelection is full path
p_astrDirs = System.IO.Directory.GetDirectories(p_strSelection)
p_astrFiles = System.IO.Directroy.GetFiles(p_strSelection)
How that helps...
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask the NT Pro at <http://www.devx.com/gethelp>
-
Re: Drive Listing in VB.NET
Hi L.J.,
I would use strong typing for those. eg String array for GetLogicalDrives and
DirectoryInfo and FileInfo arrays for the files. A recursive listing of files
such as this:
Imports System.IO
Sub Main()
Dim drive As String
For Each drive In Directory.GetLogicalDrives()
ListFiles(New DirectoryInfo(drive), True)
Next
End Sub
Sub ListFiles(ByVal Dir As DirectoryInfo, _
Optional ByVal Recursive As Boolean = True)
Dim File As FileInfo
Dim subDir As DirectoryInfo
If Dir.Exists Then
For Each File In Dir.GetFiles
Console.WriteLine(File.FullName)
Next
For Each subDir In Dir.GetDirectories
Console.WriteLine("Direcotry : {0}", subDir.FullName)
If Recursive Then ListFiles(subDir, True)
Next
End If
End Sub
"L.J. Johnson" <LJJohnson@SlightlyTiltedSoftware.com> wrote in message
news:3b296dfc@news.devx.com...
> Vikram,
>
> > What classes to use to get all physical drives etc ???
>
> Dim p_astrDrives as Array
> Dim p_astrDirs as Array
> Dim p_astrFiles as Array
>
> p_astrDrives = System.Environment.GetLogicalDrives()
>
> ' where p_strSelection is full path
> p_astrDirs = System.IO.Directory.GetDirectories(p_strSelection)
> p_astrFiles = System.IO.Directroy.GetFiles(p_strSelection)
>
> How that helps...
>
> --
> L.J. Johnson, Slightly Tilted Software
> Microsoft MVP (Visual Basic)
> LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
> <http://www.SlightlyTiltedSoftware.com>
> Ask the NT Pro at <http://www.devx.com/gethelp>
>
>
>
-
Re: Drive Listing in VB.NET
oops... of course there should be error handling in that recursive proc as
they may not have permissions to view the files or directories of a given path
even though the path exists.
"Bill McCarthy" <bill_mcc@iprimus.com.au> wrote in message
news:3b2b3568@news.devx.com...
> Hi L.J.,
>
> I would use strong typing for those. eg String array for GetLogicalDrives
and
> DirectoryInfo and FileInfo arrays for the files. A recursive listing of
files
> such as this:
>
> Imports System.IO
>
>
>
> Sub Main()
> Dim drive As String
> For Each drive In Directory.GetLogicalDrives()
> ListFiles(New DirectoryInfo(drive), True)
> Next
> End Sub
>
>
> Sub ListFiles(ByVal Dir As DirectoryInfo, _
> Optional ByVal Recursive As Boolean = True)
>
> Dim File As FileInfo
> Dim subDir As DirectoryInfo
>
> If Dir.Exists Then
>
> For Each File In Dir.GetFiles
> Console.WriteLine(File.FullName)
> Next
>
> For Each subDir In Dir.GetDirectories
> Console.WriteLine("Direcotry : {0}", subDir.FullName)
> If Recursive Then ListFiles(subDir, True)
> Next
>
> End If
>
> End Sub
>
-
Re: Drive Listing in VB.NET
Bill,
> I would use strong typing for those. eg String array for GetLogicalDrives
and
> DirectoryInfo and FileInfo arrays for the files. A recursive listing of
files
Got it (just changed to Option Strict <g>). BTW, whats the best way to
convert a non-string array into a string array (i.e., a dictionary object
like used in the envioronmental strings)? I'm currently using the code
below, but it seems a tad clunky.
Get
Dim p_EnvirVars As Collections.IDictionary
Dim p_colEnvirVars As Collections.ICollection
Dim p_intLoop As Int32
Dim p_astrEnvirVars() As String
p_EnvirVars = m_objSysEnvir.GetEnvironmentVariables()
p_intCount = p_EnvirVars.Count
ReDim p_astrEnvirVars(p_intCount - 1)
p_colEnvirVars = p_EnvirVars.Values
p_colEnvirVars.CopyTo(p_astrEnvirVars, 0)
Return p_astrEnvirVars
End Get
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask the NT Pro at <http://www.devx.com/gethelp>
-
Re: Drive Listing in VB.NET
Hi L.J.,
basically you've got it . Simplified:
Dim enviroVarValues As Collections.ICollection
enviroVarValues = System.Environment.GetEnvironmentVariables.Values
Dim strVars(enviroVarValues.Count - 1) As String
enviroVarValues.CopyTo(strVars, 0)
However I would question the value in doing this. You probably need to now
which var is which, so using the dictionary might be a better approach rather
than trying to dump into an array.
"L.J. Johnson" <LJJohnson@SlightlyTiltedSoftware.com> wrote in message
news:3b2c4590$1@news.devx.com...
> Bill,
>
> > I would use strong typing for those. eg String array for GetLogicalDrives
> and
> > DirectoryInfo and FileInfo arrays for the files. A recursive listing of
> files
>
> Got it (just changed to Option Strict <g>). BTW, whats the best way to
> convert a non-string array into a string array (i.e., a dictionary object
> like used in the envioronmental strings)? I'm currently using the code
> below, but it seems a tad clunky.
>
> Get
> Dim p_EnvirVars As Collections.IDictionary
> Dim p_colEnvirVars As Collections.ICollection
> Dim p_intLoop As Int32
> Dim p_astrEnvirVars() As String
>
> p_EnvirVars = m_objSysEnvir.GetEnvironmentVariables()
> p_intCount = p_EnvirVars.Count
>
> ReDim p_astrEnvirVars(p_intCount - 1)
>
> p_colEnvirVars = p_EnvirVars.Values
> p_colEnvirVars.CopyTo(p_astrEnvirVars, 0)
>
> Return p_astrEnvirVars
>
> End Get
>
> --
> L.J. Johnson, Slightly Tilted Software
> Microsoft MVP (Visual Basic)
> LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
> <http://www.SlightlyTiltedSoftware.com>
> Ask the NT Pro at <http://www.devx.com/gethelp>
>
>
>
-
Re: Drive Listing in VB.NET
Bill,
> However I would question the value in doing this. You probably need to now
> which var is which, so using the dictionary might be a better approach
rather
> than trying to dump into an array.
Nope, all I need is the string values -- thus the conversion.
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask the NT Pro at <http://www.devx.com/gethelp>
-
Re: Drive Listing in VB.NET
You can also use the System.IO.Directory.GetLogicalDrives() static method.
My question is, how do you determine the types of drives?
I want to build a treeview drive/folder selector (a la explorer window),
but I have to know what type of drive it is to set the image.
(Currently, I think I am going to have to resort to the Microsoft Scripting
Runtime.)
Ray Beckett
>Vikram,
>
>> What classes to use to get all physical drives etc ???
>
> Dim p_astrDrives as Array
> Dim p_astrDirs as Array
> Dim p_astrFiles as Array
>
> p_astrDrives = System.Environment.GetLogicalDrives()
>
> ' where p_strSelection is full path
> p_astrDirs = System.IO.Directory.GetDirectories(p_strSelection)
> p_astrFiles = System.IO.Directroy.GetFiles(p_strSelection)
>
>How that helps...
>
>--
>L.J. Johnson, Slightly Tilted Software
>Microsoft MVP (Visual Basic)
>LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
><http://www.SlightlyTiltedSoftware.com>
>Ask the NT Pro at <http://www.devx.com/gethelp>
>
>
>
-
Re: Drive Listing in VB.NET
Ray,
> You can also use the System.IO.Directory.GetLogicalDrives() static method.
> My question is, how do you determine the types of drives?
> I want to build a treeview drive/folder selector (a la explorer window),
> but I have to know what type of drive it is to set the image.
I had to use GetDriveType
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask the NT Pro at <http://www.devx.com/gethelp>
-
Re: Drive Listing in VB.NET
"L.J. Johnson" <LJJohnson@SlightlyTiltedSoftware.com> wrote:
>Ray,
>
>> You can also use the System.IO.Directory.GetLogicalDrives() static method.
>> My question is, how do you determine the types of drives?
>> I want to build a treeview drive/folder selector (a la explorer window),
>> but I have to know what type of drive it is to set the image.
>
>I had to use GetDriveType
>--
>L.J. Johnson, Slightly Tilted Software
>Microsoft MVP (Visual Basic)
>LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
><http://www.SlightlyTiltedSoftware.com>
>Ask the NT Pro at <http://www.devx.com/gethelp>
>
>
>
I wanted to avoid an API call. I figure the scripting runtime will probably
get migrated to other platforms, but not specific API calls.
I had really hoped the CLR would have some sort of functionality to cover
this.
-
Re: Drive Listing in VB.NET
Ray,
> I wanted to avoid an API call. I figure the scripting runtime will
probably
> get migrated to other platforms, but not specific API calls.
>
> I had really hoped the CLR would have some sort of functionality to cover
> this.
Yep, try finding a way in the CLR to copy/move a file/directory *to another
volume*.
Or, to create a shortcut (lnk).
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask the NT Pro at <http://www.devx.com/gethelp>
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks