diff --git a/src/ImeWlConverterCore/MainBody.cs b/src/ImeWlConverterCore/MainBody.cs index 897683cb..983d0b6c 100644 --- a/src/ImeWlConverterCore/MainBody.cs +++ b/src/ImeWlConverterCore/MainBody.cs @@ -753,9 +753,9 @@ public void Convert(IList filePathes, string outputDir) ExportContents = export.Export(wlList); for (var i = 0; i < ExportContents.Count; i++) { - string exportPath = outputDir + (outputDir.EndsWith("\\") ? "" : "\\") + - Path.GetFileNameWithoutExtension(file) + (i == 0 ? "" : i.ToString()) + - ".txt"; + if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); + string exportPath = Path.Combine(outputDir, + Path.GetFileNameWithoutExtension(file) + (i == 0 ? "" : i.ToString()) + ".txt"); FileOperationHelper.WriteFile(exportPath, export.Encoding, ExportContents[i]); } ExportContents = new List(); @@ -779,8 +779,9 @@ public void ExportToFile(string filePath) var outputDir = Path.GetDirectoryName(filePath); for (var i = 0; i < ExportContents.Count; i++) { - string exportPath = outputDir + (outputDir.EndsWith("\\") ? "" : "\\") + - Path.GetFileNameWithoutExtension(filePath) + (i == 0 ? "" : i.ToString()) + ".txt"; + if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); + string exportPath = Path.Combine(outputDir, + Path.GetFileNameWithoutExtension(filePath) + (i == 0 ? "" : i.ToString()) + ".txt"); FileOperationHelper.WriteFile(exportPath, export.Encoding, ExportContents[i]); } ExportContents = new List();