Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to: contents of cd

43 views
Skip to first unread message

rodchar

unread,
Jul 13, 2006, 8:44:02 AM7/13/06
to
hey all,

how do you programatically get the filenames of a disc in a CD R/RW Rom Drive?

thanks,
rodchar

Samuel Shulman

unread,
Jul 13, 2006, 11:23:07 AM7/13/06
to
AFAIK you can access the CD drive like any other drive but you need to know
the name of the drive d:\ or e:\

You may have to loop for each folder/sub folder to get the name of all files

There is also a way to know the type of the drive programmatically

hth,
Samuel Shulman

"rodchar" <rod...@discussions.microsoft.com> wrote in message
news:A31E47F4-A75F-433A...@microsoft.com...

za...@construction-imaging.com

unread,
Jul 13, 2006, 11:33:42 AM7/13/06
to

rodchar wrote:
> hey all,
>
> how do you programatically get the filenames of a disc in a CD R/RW Rom Drive?
>

The same way you would get the filenames from any file structured
"disk" device. Here's how I do it:

Add the following class to your project:

Imports System.IO

Public Class EnumDir

Private _Root As String
Private _Files As List(Of String)
Private _Folders As List(Of String)
Private _TotalSize As Long
Private _TotalFiles As Long
Private _TotalFolders As Long

Public Property Root() As String
Get
Return _Root
End Get
Set(ByVal value As String)
_Root = value
End Set
End Property

Public Property Files() As List(Of String)
Get
Return _Files
End Get
Set(ByVal value As List(Of String))
_Files = value
End Set
End Property

Public Property Folders() As List(Of String)
Get
Return _Folders
End Get
Set(ByVal value As List(Of String))
_Folders = value
End Set
End Property

Public Property TotalSize() As Long
Get
Return _TotalSize
End Get
Set(ByVal value As Long)
_TotalSize = value
End Set
End Property

Public Property TotalFiles() As Long
Get
Return _TotalFiles
End Get
Set(ByVal value As Long)
_TotalFiles = value
End Set
End Property

Public Property TotalFolders() As Long
Get
Return _TotalFolders
End Get
Set(ByVal value As Long)
_TotalFolders = value
End Set
End Property

Public Sub New()

_Root = ""
_Files = New List(Of String)
_Folders = New List(Of String)
_TotalSize = 0
_TotalFiles = 0
_TotalFolders = 0

End Sub

''' <summary>
''' Enumerates all Files in a Folder Tree
''' </summary>
''' <param name="Root"></param>
''' <remarks>Root Directory to Enumerate</remarks>
Public Sub New(ByVal Root As String)

_Root = Root
_Files = New List(Of String)
_Folders = New List(Of String)
_TotalSize = 0
_TotalFiles = 0
_TotalFolders = 0
Me.GetFiles(_Root)

End Sub

Public Sub GetFiles(ByVal Path As String)

Dim myDirectoryRoot As New DirectoryInfo(Path)
Dim di As DirectoryInfo
Dim fi As FileInfo
Dim lSize As Long = 0

For Each fi In myDirectoryRoot.GetFiles
_Files.Add(fi.FullName)
_TotalFiles += 1
_TotalSize += fi.Length
Next
For Each di In myDirectoryRoot.GetDirectories()
_Folders.Add(di.FullName)
_TotalFolders += 1
GetFiles(di.FullName)
Next
myDirectoryRoot = Nothing

End Sub

End Class

Then, in the code that needs this info:

Dim myFileList As New EnumDir("D:")

This, of course, assumes your CD/DVD drive is drive D:. After the class
has initialized, the myFileList.Files is a collection of all file
names, the full path name, and if needed, the myFileList.Folders is a
collection of folders. The other properties are self-explanatory.

0 new messages