Many times backups are created in a new folder with name as date etc. The following snippet checks if directory exists in the particular path and creates it
private static void CreateFolder() { //This example creates a new folder under MyDocuments string folderName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string userName = Environment.UserName; folderName = Path.Combine(folderName, userName); if (Directory.Exists(folderName) == false) { Directory.CreateDirectory(folderName); } }
How to combine two paths in .NET
The example combines two paths using Path.Combine method.
See also:
- How to Download File from Website using C# (.NET)
- Check if file exists using C# (.NET)
- Copying Files using .Net Functions
No comments:
Post a Comment