Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复文件夹路径拼写问题,单反斜杠(Windows),单斜杠(Linux) #591

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}