我有WPF應用程序。我想用日期時間格式在文件夾內創建文件夾。 我嘗試下面的代碼如何在wpf應用程序中使用datetime創建文件夾和文件
string reportPath= environment.currentDirectory+"\\Reports\\";
string datetime= Datetime.now.tostring("dd-MM-yyyy_HH:mm:tt");
string todaysDateFolder= path.combine(reportPath,datetime);
//string todaysDateFolder = reportPath+datetime+"\\"; //This opetion also try but get error
代碼來創建目錄folderlike如下
if (!Directory.Exist(reportPath))
{
Directory.createDirectory(reportpath);
Directory.createDirectory(todaysDateFolder);
}
else
{
Directory.createDirectory(todaysDateFolder); ///get error here that path format is not supported
}
如果我使用任何固定名稱,而不是最新的,它的工作原理。但我想日期格式化文件夾也文件。
您有什麼問題? – Sheridan