Wednesday, April 27, 2016 | By: nika perales

C# random filename generator

Import namespace
using System.IO;
Code
string path = @"C:\Folder\file.txt";

Console.WriteLine(path);
Console.WriteLine();

Console.WriteLine("Directory name: {0}", Path.GetDirectoryName(path));
Console.WriteLine("File name: {0}", Path.GetFileName(path));
Console.WriteLine("File name without extension: {0}", Path.GetFileNameWithoutExtension(path));
Console.WriteLine("File extension: {0}", Path.GetExtension(path));

Sample output

Directory name: C:\Folder
File name: file.txt
File name without extension: file
File extension: .txt

0 comments:

Post a Comment