diff --git a/samples/snippets/standard/io/file-names/cs/file-names.csproj b/samples/snippets/standard/io/file-names/cs/file-names.csproj new file mode 100644 index 00000000000..4dd6a49cbe8 --- /dev/null +++ b/samples/snippets/standard/io/file-names/cs/file-names.csproj @@ -0,0 +1,9 @@ + + + + Library + net8.0 + disable + + + diff --git a/samples/snippets/standard/io/file-names/cs/file-refs.cs b/samples/snippets/standard/io/file-names/cs/file-refs.cs index ad4eb5bef9a..9f646c52037 100644 --- a/samples/snippets/standard/io/file-names/cs/file-refs.cs +++ b/samples/snippets/standard/io/file-names/cs/file-refs.cs @@ -11,12 +11,11 @@ class Program @"\\LOCALHOST\c$\temp\test-file.txt", @"\\.\c:\temp\test-file.txt", @"\\?\c:\temp\test-file.txt", - @"\\.\UNC\LOCALHOST\c$\temp\test-file.txt", - @"\\127.0.0.1\c$\temp\test-file.txt" }; + @"\\.\UNC\LOCALHOST\c$\temp\test-file.txt" }; - foreach (var filename in filenames) + foreach (string filename in filenames) { - FileInfo fi = new FileInfo(filename); + FileInfo fi = new(filename); Console.WriteLine($"file {fi.Name}: {fi.Length:N0} bytes"); } } @@ -28,4 +27,3 @@ class Program // file test-file.txt: 22 bytes // file test-file.txt: 22 bytes // file test-file.txt: 22 bytes -// file test-file.txt: 22 bytes diff --git a/samples/snippets/standard/io/file-names/cs/paths.cs b/samples/snippets/standard/io/file-names/cs/paths.cs index f97209355ee..471e249ecb8 100644 --- a/samples/snippets/standard/io/file-names/cs/paths.cs +++ b/samples/snippets/standard/io/file-names/cs/paths.cs @@ -3,58 +3,58 @@ using System.Diagnostics; using System.IO; using System.Reflection; -public class Example +public class Example2 { - public static void Main(string[] args) - { - Console.WriteLine($"Current directory is '{Environment.CurrentDirectory}'"); - Console.WriteLine("Setting current directory to 'C:\\'"); + public static void Main(string[] args) + { + Console.WriteLine($"Current directory is '{Environment.CurrentDirectory}'"); + Console.WriteLine("Setting current directory to 'C:\\'"); - Directory.SetCurrentDirectory(@"C:\"); - string path = Path.GetFullPath(@"D:\FY2018"); - Console.WriteLine($"'D:\\FY2018' resolves to {path}"); - path = Path.GetFullPath(@"D:FY2018"); - Console.WriteLine($"'D:FY2018' resolves to {path}"); + Directory.SetCurrentDirectory(@"C:\"); + string path = Path.GetFullPath(@"D:\FY2018"); + Console.WriteLine($"'D:\\FY2018' resolves to {path}"); + path = Path.GetFullPath(@"D:FY2018"); + Console.WriteLine($"'D:FY2018' resolves to {path}"); - Console.WriteLine("Setting current directory to 'D:\\Docs'"); - Directory.SetCurrentDirectory(@"D:\Docs"); + Console.WriteLine("Setting current directory to 'D:\\Docs'"); + Directory.SetCurrentDirectory(@"D:\Docs"); - path = Path.GetFullPath(@"D:\FY2018"); - Console.WriteLine($"'D:\\FY2018' resolves to {path}"); - path = Path.GetFullPath(@"D:FY2018"); + path = Path.GetFullPath(@"D:\FY2018"); + Console.WriteLine($"'D:\\FY2018' resolves to {path}"); + path = Path.GetFullPath(@"D:FY2018"); - // This will be "D:\Docs\FY2018" as it happens to match the drive of the current directory - Console.WriteLine($"'D:FY2018' resolves to {path}"); + // This will be "D:\Docs\FY2018" as it happens to match the drive of the current directory + Console.WriteLine($"'D:FY2018' resolves to {path}"); - Console.WriteLine("Setting current directory to 'C:\\'"); - Directory.SetCurrentDirectory(@"C:\"); + Console.WriteLine("Setting current directory to 'C:\\'"); + Directory.SetCurrentDirectory(@"C:\"); - path = Path.GetFullPath(@"D:\FY2018"); - Console.WriteLine($"'D:\\FY2018' resolves to {path}"); + path = Path.GetFullPath(@"D:\FY2018"); + Console.WriteLine($"'D:\\FY2018' resolves to {path}"); - // This will be either "D:\FY2018" or "D:\FY2018\FY2018" in the subprocess. In the sub process, - // the command prompt set the current directory before launch of our application, which - // sets a hidden environment variable that is considered. - path = Path.GetFullPath(@"D:FY2018"); - Console.WriteLine($"'D:FY2018' resolves to {path}"); + // This will be either "D:\FY2018" or "D:\FY2018\FY2018" in the subprocess. In the sub process, + // the command prompt set the current directory before launch of our application, which + // sets a hidden environment variable that is considered. + path = Path.GetFullPath(@"D:FY2018"); + Console.WriteLine($"'D:FY2018' resolves to {path}"); - if (args.Length < 1) - { - Console.WriteLine(@"Launching again, after setting current directory to D:\FY2018"); - Uri currentExe = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase, UriKind.Absolute); - string commandLine = $"/C cd D:\\FY2018 & \"{currentExe.LocalPath}\" stop"; - ProcessStartInfo psi = new ProcessStartInfo("cmd", commandLine); ; - Process.Start(psi).WaitForExit(); + if (args.Length < 1) + { + Console.WriteLine(@"Launching again, after setting current directory to D:\FY2018"); + Uri currentExe = new(Assembly.GetExecutingAssembly().Location, UriKind.Absolute); + string commandLine = $"/C cd D:\\FY2018 & \"{currentExe.LocalPath}\" stop"; + ProcessStartInfo psi = new("cmd", commandLine); ; + Process.Start(psi).WaitForExit(); - Console.WriteLine("Sub process returned:"); - path = Path.GetFullPath(@"D:\FY2018"); - Console.WriteLine($"'D:\\FY2018' resolves to {path}"); - path = Path.GetFullPath(@"D:FY2018"); - Console.WriteLine($"'D:FY2018' resolves to {path}"); - } - Console.WriteLine("Press any key to continue... "); - Console.ReadKey(); - } + Console.WriteLine("Sub process returned:"); + path = Path.GetFullPath(@"D:\FY2018"); + Console.WriteLine($"'D:\\FY2018' resolves to {path}"); + path = Path.GetFullPath(@"D:FY2018"); + Console.WriteLine($"'D:FY2018' resolves to {path}"); + } + Console.WriteLine("Press any key to continue... "); + Console.ReadKey(); + } } // The example displays the following output: // Current directory is 'C:\Programs\file-paths' @@ -81,4 +81,4 @@ public class Example // 'D:FY2018' resolves to D:\Docs\FY2018 // Setting current directory to 'C:\' // 'D:\FY2018' resolves to D:\FY2018 -// 'D:FY2018' resolves to D:\FY2018\FY2018 \ No newline at end of file +// 'D:FY2018' resolves to D:\FY2018\FY2018 diff --git a/samples/snippets/standard/io/file-names/cs/rename.cs b/samples/snippets/standard/io/file-names/cs/rename.cs index b263eeca818..4c70ee673e5 100644 --- a/samples/snippets/standard/io/file-names/cs/rename.cs +++ b/samples/snippets/standard/io/file-names/cs/rename.cs @@ -1,10 +1,10 @@ using System.IO; -class Example +class Example3 { - static void Main() - { - var fi = new FileInfo(@".\test.txt"); - fi.MoveTo(@".\Test.txt"); - } + static void Main() + { + var fi = new FileInfo(@".\test.txt"); + fi.MoveTo(@".\Test.txt"); + } } diff --git a/samples/snippets/standard/io/file-names/vb/file-names.vbproj b/samples/snippets/standard/io/file-names/vb/file-names.vbproj new file mode 100644 index 00000000000..5dcc936613a --- /dev/null +++ b/samples/snippets/standard/io/file-names/vb/file-names.vbproj @@ -0,0 +1,9 @@ + + + + Library + vb + net8.0 + + + diff --git a/samples/snippets/standard/io/file-names/vb/file-refs.vb b/samples/snippets/standard/io/file-names/vb/file-refs.vb index 4aab0326218..5d3cd21bede 100644 --- a/samples/snippets/standard/io/file-names/vb/file-refs.vb +++ b/samples/snippets/standard/io/file-names/vb/file-refs.vb @@ -8,8 +8,7 @@ Module Program "\\LOCALHOST\c$\temp\test-file.txt", "\\.\c:\temp\test-file.txt", "\\?\c:\temp\test-file.txt", - "\\.\UNC\LOCALHOST\c$\temp\test-file.txt", - "\\127.0.0.1\c$\temp\test-file.txt"} + "\\.\UNC\LOCALHOST\c$\temp\test-file.txt"} For Each filename In filenames Dim fi As New FileInfo(filename) diff --git a/samples/snippets/standard/io/file-names/vb/paths.vb b/samples/snippets/standard/io/file-names/vb/paths.vb index 13cc752eea1..a51512c163b 100644 --- a/samples/snippets/standard/io/file-names/vb/paths.vb +++ b/samples/snippets/standard/io/file-names/vb/paths.vb @@ -1,8 +1,7 @@ -Imports System.Diagnostics -Imports System.IO +Imports System.IO Imports System.Reflection -Public Module Example +Public Module Example2 Public Sub Main(args() As String) Console.WriteLine($"Current directory is '{Environment.CurrentDirectory}'") diff --git a/samples/snippets/standard/io/file-names/vb/rename.vb b/samples/snippets/standard/io/file-names/vb/rename.vb index 162bb14e652..d7a410f9c4d 100644 --- a/samples/snippets/standard/io/file-names/vb/rename.vb +++ b/samples/snippets/standard/io/file-names/vb/rename.vb @@ -1,6 +1,6 @@ Imports System.IO -Module Example +Module Example3 Public Sub Main() Dim fi As New FileInfo(".\test.txt") fi.MoveTo(".\Test.txt")