Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

DeleteEmptySubdirectories (with recursive=true) throws System.IO.DirectoryNotFoundException #325

Closed
kryvoplias opened this issue May 26, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@kryvoplias
Copy link

kryvoplias commented May 26, 2017

Hi all,

I'm trying to delete all empty directories and sub-directories by using Directory.DeleteEmptySubdirectories with recursive flag.

But I'm getting exception System.IO.DirectoryNotFoundException with following message: "(3) The system cannot find the path specified: [\?\c:\temp\test\Foo\FooBar*]"

To reproduce, create following folders (Powershell):

New-Item -ItemType Directory c:\temp\test
New-Item -ItemType Directory c:\temp\test\Foo
New-Item -ItemType Directory c:\temp\test\Foo\FooFoo
New-Item -ItemType Directory c:\temp\test\Foo\FooBar
New-Item -ItemType Directory c:\temp\test\Bar

Then execute:

[Alphaleonis.Win32.Filesystem.Directory]::DeleteEmptySubdirectories("c:\temp\test", $true)
// even after exception all folders get deleted except C:\Temp\test\Foo.

Unhandled Exception: System.IO.DirectoryNotFoundException:

Unhandled Exception: System.IO.DirectoryNotFoundException: (3) The system cannot find the path specified: [\\?\c:\temp\test\Foo\FooBar\*]
   at Alphaleonis.Win32.NativeError.ThrowException(UInt32 errorCode, String readPath, String writePath) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\NativeError.cs:line 83
   at Alphaleonis.Win32.Filesystem.FindFileSystemEntryInfo.FindFirstFile(String pathLp, WIN32_FIND_DATA& win32FindData) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\FindFileSystemEntryInfo.cs:line 120
   at Alphaleonis.Win32.Filesystem.FindFileSystemEntryInfo.<Enumerate>d__3`1.MoveNext() in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\FindFileSystemEntryInfo.cs:line 229
   at Alphaleonis.Win32.Filesystem.Directory.DeleteEmptySubdirectoriesCore(FileSystemEntryInfo fileSystemEntryInfo, KernelTransaction transaction, String path, Boolean recursive, Boolean ignoreReadOnly, Boolean initialize, PathFormat pathFormat) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs:line 197
   at Alphaleonis.Win32.Filesystem.Directory.DeleteEmptySubdirectoriesCore(FileSystemEntryInfo fileSystemEntryInfo, KernelTransaction transaction, String path, Boolean recursive, Boolean ignoreReadOnly, Boolean initialize, PathFormat pathFormat) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs:line 197
   at Alphaleonis.Win32.Filesystem.Directory.DeleteEmptySubdirectories(String path, Boolean recursive) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs:line 41
   at ConsoleApplication.Program.Main(String[] args) in c:\users\developer\documents\visual studio 2015\Projects\ConsoleApplication\ConsoleApplication\Program.cs:line 14

If execute this again:

[Alphaleonis.Win32.Filesystem.Directory]::DeleteEmptySubdirectories("c:\temp\test", $true)
// after second exception all folders in C:\Temp\test are now deleted.

Unhandled Exception: System.IO.DirectoryNotFoundException:

Unhandled Exception: System.IO.DirectoryNotFoundException: (3) The system cannot find the path specified: [\\?\c:\temp\test\Foo\*]
   at Alphaleonis.Win32.NativeError.ThrowException(UInt32 errorCode, String readPath, String writePath) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\NativeError.cs:line 83
   at Alphaleonis.Win32.Filesystem.FindFileSystemEntryInfo.FindFirstFile(String pathLp, WIN32_FIND_DATA& win32FindData) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\FindFileSystemEntryInfo.cs:line 120
   at Alphaleonis.Win32.Filesystem.FindFileSystemEntryInfo.<Enumerate>d__3`1.MoveNext() in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\FindFileSystemEntryInfo.cs:line 229
   at Alphaleonis.Win32.Filesystem.Directory.DeleteEmptySubdirectoriesCore(FileSystemEntryInfo fileSystemEntryInfo, KernelTransaction transaction, String path, Boolean recursive, Boolean ignoreReadOnly, Boolean initialize, PathFormat pathFormat) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs:line 197
   at Alphaleonis.Win32.Filesystem.Directory.DeleteEmptySubdirectories(String path, Boolean recursive) in D:\Coding\Projects\GitHub\AlphaFS\AlphaFS\Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs:line 41
   at ConsoleApplication.Program.Main(String[] args) in c:\users\developer\documents\visual studio 2015\Projects\ConsoleApplication\ConsoleApplication\Program.cs:line 14
@Yomodo
Copy link
Collaborator

Yomodo commented May 26, 2017

Confirmed.
It seems that the upcoming v2.1.3 release fixes this bug.

Update: The fix will be in v2.2

@Yomodo Yomodo added this to the Release 2.1.3 milestone May 26, 2017
@Yomodo Yomodo self-assigned this Jun 2, 2017
@Yomodo Yomodo modified the milestones: vNext, Release 2.1.3 Jun 2, 2017
@kryvoplias
Copy link
Author

Seems like this bug is now fixed in 2.1.3

@Yomodo
Copy link
Collaborator

Yomodo commented Jun 8, 2017

Weird, I still get a DirectoryNotFoundException.

@kryvoplias
Copy link
Author

That's really weird. After updating to v2.1.3 everything was OK, but after reboot tests became red again.

@Yomodo Yomodo closed this as completed Jun 26, 2017
@Yomodo Yomodo modified the milestones: vNext, Release 2.2 Jan 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants