public static void CreateFolder()
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); //Gets desktop folder
string pathTo = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "/" + "SYS_" + Random6CharString() + "/"; //Creates random directories
foreach(char path in Random6CharString())
{
System.IO.Directory.CreateDirectory(pathTo); //Method to create folders on Desktop
}
}
public static string Random6CharString()
{
string path = Path.GetRandomFileName();
path = path.Replace(".", ""); // Remove period.
return path.Substring(0, 6); // Return 6 character string
}
我正在制作一款游戏,它应该将文件夹写入用户桌面以用作游戏中的事件。当我想到一个点时,应该同时创建2个文件夹,它只创建一个文件夹。谁能告诉我如何一次制作多个文件夹?或者至少一个接一个地做,而不是同时做?多谢你们!将多个目录写入桌面c#?
我不确定我想玩在我的桌面上创建文件夹的游戏。 – juharr
这不是什么新鲜事,它只是不使用游戏目录文件夹,并使用更多'个人',我想你可以说。 –
如果您使用[Path.Combine](https://msdn.microsoft.com/en-us/library/system.io.path.combine%28v=vs.110%29.aspx),那么您没有担心路径分隔符字符。 –