September 29, 2003

CountFileCharacters – Counting how many characters of a given type are in a file

‘ Count how many characters of a given type are in a file’ Example:’ Dim charCount(255) As Integer’ CountFileCharacters(“c: est.txt”, charCount)’ Debug.WriteLine(“the char ‘A’ was found ” & charCount(Asc(“A”)) & ” times”)’ Debug.WriteLine(“the char ‘a’ was found ” & charCount(Asc(“a”)) & ” times”)Sub CountFileCharacters(ByVal filePath As String, ByVal charCount() As

GetUrlFromLinkFile – Retrieve the Url pointed by a link (*.url) file

‘ Get the Url pointed by the input link (*.url) file” Example: print the Url of all the link files in the Favorites folder’ Dim filePath As String’ For Each filePath In System.IO.Directory.GetFiles( ‘ ‘ Environment.GetFolderPath(Environment.SpecialFolder.Favorites), “*.url”)’ Debug.WriteLine(System.IO.Path.GetFileNameWithoutExtension(filePath) & ‘ ” = ” & GetUrlFromLinkFile(filePath))’ NextFunction GetUrlFromLinkFile(ByVal linkFile As String)

GetDriveLabel – Retrieving the label of the specified drive

‘ Retrieve the drive name (label) of the specified drive’ Note: requires a reference to the System.Management assembly’ Example: MessageBox.Show(GetDriveLabel(“D”c))Function GetDriveLabel(ByVal driveLetter As Char) As String Dim driveFilter As String = “Win32_LogicalDisk=””” & driveLetter.ToString & _ “:””” Dim drive As New System.Management.ManagementObject(driveFilter) Return drive(“VolumeName”)End Function

GetDriveSerialNumber – Retrieving the serial number of the specified drive

‘ Retrieve the serial number of the specified drive’ Note: requires a reference to the System.Management assembly’ Example: MessageBox.Show(GetDriveSerialNumber(“D”c))Function GetDriveSerialNumber(ByVal driveLetter As Char) As String Dim driveFilter As String = “Win32_LogicalDisk=””” & driveLetter.ToString & _ “:””” Dim drive As New System.Management.ManagementObject(driveFilter) Return drive(“VolumeSerialNumber”)End Function

SetFileLength – Set the length in bytes of the input file

‘ Set the length in bytes of the input file’ Example:’ Dim filePath As String = “c: est.txt”‘ MessageBox.Show(“Original length: ” & New System.IO.FileInfo(filePath)’ .Length)’ SetFileLength(filePath, 50000)’ MessageBox.Show(“New length: ” & New System.IO.FileInfo(filePath).Length)Sub SetFileLength(ByVal filePath As String, ByVal sizeInBytes As Long) Dim fs As System.IO.FileStream Try fs = New System.IO.FileStream(filePath,