Reputation: 4877
I wonder how i can create a folder and the name of the folder is a value from a string.
This
string[] directories = Directory.GetDirectories(filePath2);
foreach (string directory in directories)
{
Directory.CreateDirectory(filePath + directory);
}
or this
string[] directories = Directory.GetDirectories(filePath2);
foreach (string directory in directories)
{
Directory.CreateDirectory(filePath + @"/"+directory+"/");
}
throws a NotSupportedException
How can I do it?
Upvotes: 0
Views: 665
Reputation: 26209
Problem : if i understand correctly, you wanted to create the directories under the given path.
As others already stated it throws NotSupportedException
when there is a colon :
which is not part of the drive letter.
From MSDN : NotSupportedException
path contains a colon character (:) that is not part of a drive label ("C:\").
if you want to create a directory
under the given path, you need to extract only the directory
name(without drive path) from the directory
variable which contains overall directory path including drive path which you does not need.
Solution: You need to extract only the DirectoryName
from the directory
variable in which it contains whole directory path (which also includes drive path- which is leading to Exception)
Try This:
foreach (string directory in directories)
{
Directory.CreateDirectory(filePath + @"/" +
directory.Substring(directory.LastIndexOf("\\")) + "/");
}
Upvotes: 1
Reputation: 13411
The MSDN documents the possible exceptions along with the error conditions.
NotSupportedException
path contains a colon character (:) that is not part of a drive label ("C:\").
Upvotes: 0
Reputation: 534
As the documentation says
NotSupportedException: path contains a colon character (:) that is not part of a drive label ("C:\").
Take a look http://msdn.microsoft.com/en-us/library/9h4z99zb(v=vs.110).aspx
Upvotes: 0
Reputation: 3915
According to the documentation on MSDN ( http://msdn.microsoft.com/en-us/library/54a0at6s(v=vs.110).aspx ) a NotSupportedException
is raised when a "path contains a colon character (:) that is not part of a drive label ("C:\")." Check what is the content of your string.
Also in this regard remember:
Upvotes: 2