做Path.GetTempFileName创建的文件会自动清理?文件、Path、GetTempFileName

由网友(乱了夏天蓝了海#)分享简介:我一直认为答案是肯定的,但现在我试图找到真相。I've always assumed the answer is yes, but now I'm trying to find the truth.当我使用创建一个临时文件 Path.GetTempFileName(),将窗户自动后清理一下?When I crea...

我一直认为答案是肯定的,但现在我试图找到真相。

I've always assumed the answer is yes, but now I'm trying to find the truth.

当我使用创建一个临时文件 Path.GetTempFileName(),将窗户自动后清理一下?

When I create a temp file using Path.GetTempFileName(), will windows automatically clean that up later?

怎么样,如果我下创建 Path.GetTempPath目录()?将在Windows清理?

What about if I create a directory under Path.GetTempPath()? Will windows clean it up?

或者是开发商的责任,删除已创建有文件吗?

Or is it the developer's responsibility to delete files created there?

推荐答案

没有它们不会自动删除。为了创建关闭时会被自动删除的文件,通过 FILE_FLAG_DELETE_ON_CLOSE 到CreateFile.

No they do not get deleted automatically. In order to create a file that will be deleted automatically when it is closed, pass FILE_FLAG_DELETE_ON_CLOSE to CreateFile.

该文件将被立即删除后,它的所有句柄被关闭,其中包括指定的手柄以及其他任何打开或复制的句柄。   若存在打开的句柄到一个文件中,呼叫失败,除非他们都打开了 FILE_SHARE_DELETE 共享模式。   该文件随后打开请求失败,除非指定了 FILE_SHARE_DELETE 共享模式。

The file is to be deleted immediately after all of its handles are closed, which includes the specified handle and any other open or duplicated handles. If there are existing open handles to a file, the call fails unless they were all opened with the FILE_SHARE_DELETE share mode. Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified.

为了能够访问来自.NET这个Win32的功能,使用SafeFileHandle类。

In order to gain access to this Win32 functionality from .net, use the SafeFileHandle class.

阅读全文

相关推荐

最新文章