Skip to content

Commit

Permalink
Merge pull request #591 from itsvse/master
Browse files Browse the repository at this point in the history
修复文件夹路径拼写问题,单反斜杠(Windows),单斜杠(Linux)
  • Loading branch information
tonyqus committed Aug 20, 2021
2 parents 95efbba + cd1d18d commit e34ad28
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions main/Util/TempFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


namespace NPOI.Util
{
using System;
Expand All @@ -21,13 +21,13 @@ public static FileInfo CreateTempFile(String prefix, String suffix)

if (dir == null)
{
dir = Directory.CreateDirectory(Path.GetTempPath() + @"\poifiles").FullName;
dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "poifiles")).FullName;
}
// Generate a unique new filename
string file= dir + "\\" + prefix + Guid.NewGuid().ToString() + suffix;
string file = Path.Combine(dir, prefix + Guid.NewGuid().ToString() + suffix);
while (File.Exists(file))
{
file = dir + "\\" + prefix + Guid.NewGuid().ToString() + suffix;
file = Path.Combine(dir, prefix + Guid.NewGuid().ToString() + suffix);
Thread.Sleep(1);
}
FileStream newFile = new FileStream(file, FileMode.CreateNew, FileAccess.ReadWrite);
Expand All @@ -40,12 +40,12 @@ public static string GetTempFilePath(String prefix, String suffix)
{
if (dir == null)
{
dir = Directory.CreateDirectory(Path.GetTempPath() + @"\poifiles").FullName;
dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "poifiles")).FullName;
}
Random rnd = new Random(DateTime.Now.Millisecond);
Thread.Sleep(10);
//return prefix + rnd.Next() + suffix;
return dir + "\\" + prefix + rnd.Next() + suffix;
return Path.Combine(dir, prefix + rnd.Next() + suffix);
}
}
}

0 comments on commit e34ad28

Please sign in to comment.