VB.Net ファイル操作 [.NET]

.Netでフォルダやファイルの削除、存在チェックは以下のようにできます。

.NETファイル操作

ファイル操作
1
2
3
4
5
6
7
8
9
System.IO.Directory.Delete(sPath)         'フォルダ削除'
System.IO.Directory.CreateDirectory(sPath)  'フォルダ作成'
 
'フォルダ存在確認'
If System.IO.Directory.Exists(sPath) Then
  MsgBox("存在します。", vbInformation)
Else
  MsgBox("存在しません。", vbExclamation)
End If

.NETフォルダ操作

フォルダ操作
1
2
3
4
5
6
7
8
9
System.IO.File.Delete(sPath)                 'ファイル削除'
System.IO.File.Copy(sPathFrom, sPathTo)      'ファイルコピー'
 
'ファイル存在確認'
If System.IO.File.Exists(sPath) Then
  MsgBox("存在します。", vbInformation)
Else
  MsgBox("存在しません。", vbExclamation)
End If

便利ですね。

コメント

人気の投稿