My.Computer.FileSystem には、ファイル操作に便利な関数がたくさん入っています。
いくつかオーバーロードしている関数もありますが、ここでは簡単な(基本的な)記述だけ紹介します。
パスの結合
My.Computer.FileSystem.CombinePath(baseDirectory As String, relativePath As String)
ディレクトリのコピー
My.Computer.FileSystem.CopyDirectory(sourceDirectoryName As String ,destinationDirectoryName As String )
ファイルのコピー
My.Computer.FileSystem.CopyFile(sourceFileName As String ,destinationFileName As String )
ディレクトリの作成
My.Computer.FileSystem.CreateDirectory(directory As String )
カレントディレクトリの取得 (戻り値はString)
My.Computer.FileSystem.CurrentDirectory()
ディレクトリの削除
My.Computer.FileSystem.DeleteDirectory(directory As String ,onDirectoryNotEmpty As DeleteDirectoryOption )
ファイルの削除
My.Computer.FileSystem.DeleteFile(file As String)
ディレクトリが存在するかの確認 (戻り値はBoolern)
My.ComputerFileSystem.DirectoryExists(directory As String)
ファイルが存在するかの確認 (戻り値はBoolern)
My.Computer.FileSystem.FileExists(file As String)
ファイルから特定の文字列を検索(?)
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.FindInFiles(directory As String ,containsText As String ,ignoreCase As Boolern ,searchType As SearchOption )
ディレクトリの取得(?)
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetDirectories(directory As String)
ディレクトリ情報の取得
Dim returnValue As DirectoryInfo
returnValue = My.Computer.FileSystem.GetDirectoryInfo(directory As String)
ドライブ情報の取得
Dim returnValue As DriveInfo
returnValue = My.Computer.FileSystem.GetDriveInfo(drive As String)
ファイル情報の取得
Dim returnValue As FileInfo
returnValue = My.Computer.FileSystem.GetFileInfo(file As String)
指定されたディレクトリ中にあるファイルの取得(コレクションで返る?)
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(directory As String)
ファイル名の取得
Dim returnValue As String
returnValue = My.Computer.FileSystem.GetName(path As String)
ファイル名までのパスを返す(直前のパスを返す?)
Dim strPath As String
strPath = My.Computer.FileSystem.GetParentPath(path As String)
ディレクトリの移動
My.Computer.FileSystem.MoveDirectory(sourceDirectoryName As String ,destinationDirectoryName As String)
ファイルの移動
My.Computer.FileSystem.MoveFile(sourceFileName As String,destinationFileName As String)
ファイルの内容をByte型で取得
Dim returnValue() As Byte
returnValue = My.Computer.FileSystem.ReadAllBytes(file As String)
ファイルの内容をString型で取得
Dim value As String
value = My.Computer.FileSystem.ReadAllText(file As String)
ディレクトリ名の変更
My.Computer.FileSystem.RenameDirectory(directory As String, newName As String)
ファイル名の変更
My.Computer.FileSystem.RenameFile(file As String, newName As String)
Byte型のデータをファイルへ書き込む
My.Computer.FileSystem.WriteAllBytes(file As String, data() As Byte , append As Boolern)
String型のデータをファイルへ書き込む
My.Computer.FileSystem.WriteAllText(file As String ,text As String ,append As Boolern)
つ…疲れた…