做Path.GetTempFileName创建的文件会自动清理? [英] Do files created with Path.GetTempFileName get cleaned up automatically?

查看:1075
本文介绍了做Path.GetTempFileName创建的文件会自动清理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 到<一个href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx"><$c$c>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的功能,使用<一个href="http://msdn.microsoft.com/en-us/library/microsoft.win32.safehandles.safefilehandle.aspx"><$c$c>SafeFileHandle类。

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

这篇关于做Path.GetTempFileName创建的文件会自动清理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆