Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

RemoveDirectoryW function (fileapi.h)

  • 2024-01-04
Feedback

In this article

Deletes an existing empty directory.

To perform this operation as a transacted operation, use theRemoveDirectoryTransacted function.

Syntax

BOOL RemoveDirectoryW(  [in] LPCWSTR lpPathName);

Parameters

[in] lpPathName

The path of the directory to be removed. This path must specify an empty directory, and the calling process must have delete access to the directory.

By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path. For more information, seeNaming Files, Paths, and Namespaces.

Tip

Starting with Windows 10, Version 1607, you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section ofNaming Files, Paths, and Namespaces for details.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

Remarks

TheRemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed.

To recursively delete the files in a directory, use theSHFileOperation function.

RemoveDirectory can be used to remove a directory junction. Since the target directory and its contents will remain accessible through its canonical path, the target directory itself is not affected by removing a junction which targets it. For this reason, whenlpPathName refers to a directory junction,RemoveDirectory will remove the specified link regardless of whether the target directory is empty or not. For more information on junctions, seeHard Links and Junctions.

The use of POSIX delete causes the directory to be deleted while handles remain open. Subsequent calls toCreateDirectory to open the directory fail withERROR_FILE_NOT_FOUND.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

TechnologySupported
Server Message Block (SMB) 3.0 protocolYes
SMB 3.0 Transparent Failover (TFO)Yes
SMB 3.0 with Scale-out File Shares (SO)Yes
Cluster Shared Volume File System (CsvFS)Yes
Resilient File System (ReFS)Yes

Note

Thefileapi.h header defines RemoveDirectory as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, seeConventions for Function Prototypes.

Requirements

RequirementValue
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headerfileapi.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See also

CreateDirectory

Creating and Deleting Directories

Directory Management Functions

RemoveDirectoryTransacted


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo