1 out of 1 rated this helpful - Rate this topic

DeleteFileTransacted function

[Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using Transactional NTFS.]

Applies to: desktop apps only

Deletes an existing file as a transacted operation.

Syntax

BOOL WINAPI DeleteFileTransacted(
  __in  LPCTSTR lpFileName,
  __in  HANDLE hTransaction
);

Parameters

lpFileName [in]

The name of the file to be deleted.

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE.

hTransaction [in]

A handle to the transaction. This handle is returned by the CreateTransaction function.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.

Remarks

If an application attempts to delete a file that does not exist, the DeleteFileTransacted function fails with ERROR_FILE_NOT_FOUND. If the file is a read-only file, the function fails with ERROR_ACCESS_DENIED.

The following list identifies some tips for deleting, removing, or closing files:

  • To delete a read-only file, first you must remove the read-only attribute.
  • To delete or rename a file, you must have either delete permission on the file, or delete child permission in the parent directory.
  • To recursively delete the files in a directory, use the SHFileOperation function.
  • To remove an empty directory, use the RemoveDirectoryTransacted function.
  • To close an open file, use the CloseHandle function.

If you set up a directory with all access except delete and delete child, and the access control lists (ACL) of new files are inherited, then you can create a file without being able to delete it. However, then you can create a file, and then get all the access you request on the handle that is returned to you at the time you create the file.

If you request delete permission at the time you create a file, you can delete or rename the file with that handle, but not with any other handle. For more information, see File Security and Access Rights.

The DeleteFileTransacted function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.

The DeleteFileTransacted function marks a file for deletion on close. The file is deleted after the last transacted writer handle to the file is closed, provided that the transaction is still active. If a file has been marked for deletion and a transacted writer handle is still open after the transaction completes, the file will not be deleted.

Symbolic links:  If the path points to a symbolic link, the symbolic link is deleted, not the target. To delete a target, you must call CreateFile and specify FILE_FLAG_DELETE_ON_CLOSE.

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

DeleteFileTransactedW (Unicode) and DeleteFileTransactedA (ANSI)

See also

CloseHandle
CreateFileTransacted
File Management Functions
Symbolic Links
Transactional NTFS

 

 

Send comments about this topic to Microsoft

Build date: 4/17/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
C# syntax
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
internal static extern bool DeleteFileTransacted([In] string lpFileName, [In] KtmTransactionHandle hTransaction);
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> Public Shared Function DeleteFileTransacted(<[In]> ByVal lpFileName As String, <[In]> ByVal hTransaction As KtmTransactionHandle) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function