Skip to content

Commit a05695f

Browse files
Copilotgewarren
andcommitted
Move System.IO VB snippets to new organization
Co-authored-by: gewarren <[email protected]>
1 parent 3bc6f0b commit a05695f

File tree

21 files changed

+452
-10
lines changed

21 files changed

+452
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
' <snippet1>
2+
Imports System.IO
3+
4+
Public Class CreateSubTest
5+
6+
Public Shared Sub Main()
7+
' Make a reference to a directory.
8+
Dim di As New DirectoryInfo("TempDir")
9+
10+
' Create the directory only if it does not already exist.
11+
If di.Exists = False Then
12+
di.Create()
13+
End If
14+
15+
' Create a subdirectory in the directory just created.
16+
Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")
17+
18+
' Process that directory as required.
19+
' ...
20+
21+
' Delete the subdirectory.
22+
dis.Delete(True)
23+
24+
' Delete the directory.
25+
di.Delete(True)
26+
End Sub
27+
End Class
28+
' </snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
' <snippet1>
2+
Imports System.IO
3+
4+
Public Class DeleteTest
5+
6+
Public Shared Sub Main()
7+
' Make a reference to a directory.
8+
Dim di As New DirectoryInfo("TempDir")
9+
10+
' Create the directory only if it does not already exist.
11+
If di.Exists = False Then
12+
di.Create()
13+
End If
14+
15+
Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")
16+
' Create a subdirectory in the directory just created.
17+
18+
' Process that directory as required.
19+
' ...
20+
21+
' Delete the subdirectory. The true indicates that if subdirectories
22+
' or files are in this directory, they are to be deleted as well.
23+
dis.Delete(True)
24+
25+
' Delete the directory.
26+
di.Delete(True)
27+
End Sub
28+
End Class
29+
' </snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
' <snippet1>
2+
Imports System.IO
3+
4+
Public Class GetDirectoriesTest
5+
6+
Public Shared Sub Main()
7+
' Make a reference to a directory.
8+
Dim di As New DirectoryInfo("c:\")
9+
' Get a reference to each directory in that directory.
10+
Dim diArr As DirectoryInfo() = di.GetDirectories()
11+
' Display the names of the directories.
12+
Dim dri As DirectoryInfo
13+
For Each dri In diArr
14+
Console.WriteLine(dri.Name)
15+
Next dri
16+
End Sub
17+
End Class
18+
' </snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'<snippet1>
2+
Imports System.IO
3+
4+
Public Class MoveToTest
5+
6+
Public Shared Sub Main()
7+
' Make a reference to a directory.
8+
Dim di As New DirectoryInfo("TempDir")
9+
' Create the directory only if it does not already exist.
10+
If di.Exists = False Then
11+
di.Create()
12+
End If
13+
14+
' Create a subdirectory in the directory just created.
15+
Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")
16+
If Directory.Exists("NewTempDir") = False Then
17+
' Move the main directory. Note that the contents move with the directory.
18+
di.MoveTo("NewTempDir")
19+
End If
20+
Try
21+
' Attempt to delete the subdirectory. Note that because it has been
22+
' moved, an exception is thrown.
23+
dis.Delete(True)
24+
Catch
25+
' Handle this exception in some way, such as with the following code:
26+
' Console.WriteLine("That directory does not exist.");
27+
' Point the DirectoryInfo reference to the new directory.
28+
' di = New DirectoryInfo("NewTempDir")
29+
' Delete the directory.
30+
' di.Delete(True)
31+
End Try
32+
33+
End Sub
34+
End Class
35+
'</snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'<snippet1>
2+
Imports System.IO
3+
4+
Public Class MoveToTest
5+
6+
Public Shared Sub Main()
7+
' Make a reference to a directory.
8+
Dim di As New DirectoryInfo("TempDir")
9+
' Create the directory only if it does not already exist.
10+
If di.Exists = False Then
11+
di.Create()
12+
End If
13+
14+
' Create a subdirectory in the directory just created.
15+
Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")
16+
17+
' Get a reference to the parent directory of the subdirectory you just made.
18+
Dim parentDir As DirectoryInfo = dis.Parent
19+
Console.WriteLine("The parent directory of '{0}' is '{1}'", dis.Name, parentDir.Name)
20+
21+
' Delete the parent directory.
22+
di.Delete(True)
23+
End Sub
24+
End Class
25+
'</snippet1>

0 commit comments

Comments
 (0)